简体   繁体   中英

How can I add a empty attribute to my video tag?

I just would like to add the 'autobuffer' attribute to my video tag using javascript.

Basically:

var video = document.createElement('video');
video.addAttribute('autoBuffer');

And I'll have:

<video autoBuffer></video>

I tried:

video.setAttribute('autoBuffer'); => <video autoBuffer="undefined"></video>

Which is wrong...

The second parameter to setAttribute must be a string always - currently the undefined you're implicitly passing is converted to one. Use

video.setAttribute('autoBuffer', '');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM