我收到了以下HTML:
<video width="552" height="572" id="video" autoplay preload="none" poster="image.png">
如何完全从autoplay
元素中删除<video>
?
我尝试过以下内容:
//Attempt
jQuery('video').remove('autoplay');
//Attempt
jQuery( 'video' ).removeClass( 'autoplay' );
答案 0 :(得分:11)
删除:
普通javascript:
document.getElementsByTagName('video')[0].removeAttribute('autoplay');
OR
document.getElementById('VIDEO_ID').removeAttribute('autoplay');
使用jQuery:
$('video').removeAttr("autoplay");
添加:
普通javascript:
document.getElementsByTagName('video')[0].setAttribute('autoplay','');
OR
document.getElementById('VIDEO_ID').setAttribute('autoplay','');
使用jQuery:
$('video').attr("autoplay","");
答案 1 :(得分:6)
autoplay
是一个属性,因此使用removeAttr
属性。
http://api.jquery.com/removeAttr/
$(selector).removeAttr('autoplay');
答案 2 :(得分:1)
您可以使用.removeAttr()
方法执行此操作:
jQuery( 'video' ).removeAttr( 'autoplay' );
这将从每个autoplay
元素中删除video
属性。
jQuery( '#video' ).removeAttr( 'autoplay' );
这会从 ID autoplay
的元素中删除video
属性。
答案 3 :(得分:1)
您可以使用.removeAttr()
功能。
jQuery('video').removeAttr('autoplay');
没有测试但应该工作
答案 4 :(得分:0)
尝试:
jquery('video').removeAttr('autoplay');