javascript - currentSrc 在 jquery 插件中不起作用

标签 javascript jquery html5-video

“currentSrc”是我必须在具有多个源(*.mp3、*.ogg 等)的 html5 视频中切换源 src 的唯一选项

如果我在 Jquery 中使用,“currentSrc”会抛出“undefined”。 但它工作正常,如果我在 html 页面中调用它。

详细说明: 我的视频来源:

<video width="630" height="354" id="video1" class="video1" poster="asserts/poster.png" controls="controls" data-name="demo video" data-uid="57fb2708">
        <source src="http://static.clipcanvas.com/sample/clipcanvas_14348_H264_320x180.mp4" data-quality="sd" />
        <source src="asserts/samllfile.mp4" data-quality="hd" />
        <source src="http://static.clipcanvas.com/elephants-dream.webm" data-quality="hd" />
        <source src="http://video.webmfiles.org/big-buck-bunny_trailer.webm" data-quality="sd"/>
        <source src="http://video.webmfiles.org/elephants-dream.webm" data-quality="hd" />
</video>

获取当前视频地址

html 页面中的 Javascript(工作正常):

myVid=document.getElementById("video1");
    function getVid(){
        alert(myVid.currentSrc);
    };

Jquery 中的行(抛出“undefined”):

alert($hdVideo.currentSrc);

请帮帮我...

最佳答案

因为 jQuery 对象没有属性 currentSrc 所以它返回 undefined。

alert( $hdVideo.get(0).currentSrc );
alert( $hdVideo[0].currentSrc );
alert( $hdVideo.prop("currentSrc") );   //might be attr() instead of prop()

关于javascript - currentSrc 在 jquery 插件中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12748950/

相关文章:

javascript - 创建 4 个(打开和关闭)按钮,每个按钮修改一个段落

javascript - 第一个空格后的 jquery 跨度

javascript - 在 anchor 链接到另一个页面并显示 div

javascript - 如何将子菜单添加到单击的按钮

javascript - 我的 Firefox 不支持 HTML5 视频,但可以在其他地方使用

javascript - 更改 Cookie 脚本

javascript - jQuery 缩略图滚动条溢出

javascript - 如何在php中屏蔽javascript字符串

google-chrome - Chrome 不会提出额外的视频文件请求

css - .flex-video 的 Flexbox 错误