本文介绍了JavaScript仅在具有警报时起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码在播放器中加载youtubevidéo。
The following code loads a youtube vidéo in a player.
如果我删除了两个警报,它将不再起作用...
If I remove the two "alert", it doesn't work anymore...
ytplayer = document.getElementById("ytPlayer"); alert('ok'); if (ytplayer) { alert('ok'); loadVideo(url, start); }有人可以帮助我吗?
推荐答案您可能在页面加载之前调用了代码。有了警报,js执行将停止,从而允许页面加载。如果正确,则需要查看 window.onload 回调或可能的 document.ready
you are probably invoking the code before the page loads. With the alert, js execution stops, allowing the page to load. If this is correct, you need to look into the window.onload callback or possibly document.ready
window.onload = function(){ // load the vid here }更多推荐
JavaScript仅在具有警报时起作用
发布评论