javascript 从 <video> 元素中删除“自动播放”属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19519084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove "autoplay" attribute from <video> element
提问by user1231561
I got the following HTML:
我得到以下 HTML:
<video width="552" height="572" id="video" autoplay preload="none" poster="image.png">
How would I go about removing autoplay
entirely from the <video>
element?
我将如何autoplay
从<video>
元素中完全删除?
I've tried something like the following:
我试过类似以下的东西:
//Attempt
jQuery('video').remove('autoplay');
//Attempt
jQuery( 'video' ).removeClass( 'autoplay' );
回答by Vicky Gonsalves
to Remove:
去除:
plain javascript:
普通的javascript:
document.getElementsByTagName('video')[0].removeAttribute('autoplay');
OR
或者
document.getElementById('VIDEO_ID').removeAttribute('autoplay');
With jQuery:
使用 jQuery:
$('video').removeAttr("autoplay");
To Add:
添加:
plain javascript:
普通的javascript:
document.getElementsByTagName('video')[0].setAttribute('autoplay','');
OR
或者
document.getElementById('VIDEO_ID').setAttribute('autoplay','');
With jQuery:
使用 jQuery:
$('video').attr("autoplay","");
回答by Thew
autoplay
Is an attribute, therefor use the removeAttr
attribute.
autoplay
是一个属性,因此使用该removeAttr
属性。
http://api.jquery.com/removeAttr/
http://api.jquery.com/removeAttr/
$(selector).removeAttr('autoplay');
$(selector).removeAttr('autoplay');
回答by pala?н
You can do this using the .removeAttr()
method:
您可以使用以下.removeAttr()
方法执行此操作:
jQuery( 'video' ).removeAttr( 'autoplay' );
This will remove the autoplay
attribute from each video
element.
这autoplay
将从每个video
元素中删除属性。
jQuery( '#video' ).removeAttr( 'autoplay' );
This will remove the autoplay
attribute from the element with IDvideo
.
这将从autoplay
具有ID的元素中删除该属性video
。
回答by Laxmana
You can use the .removeAttr()
function.
您可以使用该.removeAttr()
功能。
jQuery('video').removeAttr('autoplay');
Haven't test it but should work
还没有测试,但应该工作
回答by Rich
Try:
尝试:
jquery('video').removeAttr('autoplay');