如果我加载包含
我正在使用 HTML5 简介中的设置来显示带有自定义控件的 元素。 (参见
http://introducinghtml5.com/examples/ch04/custom-controls.html
中的示例)。
我过去曾成功地使用过它。不过,这次的不同之处在于,我将 元素包含在由 AJAX 加载的一段 HTML 中。该元素已加载,但应用自定义控件的 JavaScript 失败。记录视频变量(定义为“
var video = document.getElementsByTagName('video')[0]
”)会返回undefined
。
我认为因为 在初始页面加载时不存在,所以该变量将始终是未定义的。但是是否有另一种方法来选择它以便定义我的视频变量?
I'm using the set-up from Introducing HTML5 to display a <video>
element with custom controls. (See example at http://introducinghtml5.com/examples/ch04/custom-controls.html
).
I have used it successfully in the past. However, the difference this time is that I am including the <video>
element in a piece of HTML that is loaded by AJAX. The element loads, but the javascript that applies the custom controls fails. Logging the video variable (which is defined as "var video = document.getElementsByTagName('video')[0]
") returns undefined
.
I think that because the <video>
is not present on the initial page load, that variable will always be undefined. But is there perhaps another way to select it so that my video variable will be defined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将需要访问视频元素的代码移至 ajax 请求的完成或成功回调内部。
You need to move the code that needs access to the video element to inside the complete or success callback of the ajax request.