在 document.ready、jquery 中调用函数
我有这样的代码
<script>$(document).ready(function(){
var myPlayList = [];
//document.write(whatTo);
//New instance of jPlayerSkin
var skin = new jPlayerSkin( '#jplayer_container' , myPlayList );
//Start the player
skin.initialize();
});
</script>
,并且有函数,即 function updatePlaylist(song,title,url) { /* code */ }
现在我想要的就是在 document.ready 中执行此 updatePlaylist 函数因为在这个函数中我还调用了 Skin.add() ,它仅在 document.ready 中可用。但是当我将函数放在 document.ready() 中时,我无法执行它,如果我将它放在外面,我可以执行该函数,但它无法访问 Skin.add() 。
i have a code like this
<script>$(document).ready(function(){
var myPlayList = [];
//document.write(whatTo);
//New instance of jPlayerSkin
var skin = new jPlayerSkin( '#jplayer_container' , myPlayList );
//Start the player
skin.initialize();
});
</script>
and i have function , which is function updatePlaylist(song,title,url) { /* code */ }
Now all i want is to execute this updatePlaylist function in document.ready because in this function i also call skin.add() , which is available in document.ready only. But when i place the function in document.ready() , i can't execute it, and if i put it outside, i can execute the function but it can't access skin.add().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
var myPlayList = [];
和var Skin = null
移到文档之外。准备好后,使用updatePlaylist(song,title,url)
重试>在文档中.readymove
var myPlayList = [];
andvar skin = null
outside of the document.ready, try again withupdatePlaylist(song,title,url)
in document.ready不要将该函数放在传递给
document.ready
的函数内,这只会在本地作用域。将其保留为全局并从该函数中调用它。
Don't put the function inside the function you pass to
document.ready
, that will just locally scope it.Keep it as a global and just call it from that function.