JavaScript仅在具有警报时起作用

编程入门 行业动态 更新时间:2024-10-22 04:46:39
本文介绍了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仅在具有警报时起作用

本文发布于:2023-11-27 03:50:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!