从<video>元素</video>中删除“autoplay”属性

时间:2013-10-22 13:19:44

标签: javascript jquery

我收到了以下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' );

5 个答案:

答案 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');
相关问题