简体   繁体   English

使用jquery.load加载javascript后出错

[英]Error in javascript after load it with jquery.load

in my a.html i write this: 在我的a.html我写这个:

<script>
function Flike()
{ jQuery('#ft').load('like.php'); }
</script>

in the body of a.html i write 在a.html的身体我写

window.onload = Flike()

like.php is: like.php是:

echo " <script> var e = document.createElement('script');
e.async = true;
e.src = '/facebook/like.js';
document.getElementById('ft').appendChild(e);
</script>
";}

Still now, All fine and works. 现在,一切都很好并且有效。

the problem is in like.js the script isn't work. 问题出在like.js上,脚本不起作用。 this is like.js 这就像.js

I also tried without the document ready function... didn't work. 我也试过没有文件准备功能......没有用。

window.onload = Flike() is wrong window.onload = Flike()是错误的

It should be 它应该是

window.onload = Flike;

but if you are using jQuery, why are you not adding it 但如果您使用的是jQuery,为什么不添加它

$(window).load(Flike)

And if you are just loading a script, why are you not using 如果您只是加载脚本,为什么不使用

$.getScript("/facebook/like.js");

Finally, if you are calling this after the page load, the document.ready event will not fire again for this new script. 最后,如果您在页面加载后调用此方法,则不会再为此新脚本触发document.ready事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM