【发布时间】:2018-11-05 14:21:15
【问题描述】:
我有这个图像元素:
<img class="cat" src="img/tom.png" alt="Cat">
我想同时删除 src 和 alt 属性。
我希望removeAttribute() 方法接受多个参数,但事实并非如此。
除了这个重复的代码之外,还有其他方法吗:
image.removeAttribute('src');
image.removeAttribute('alt');
【问题讨论】:
-
你可以设置它的
outerHTML,但最好只是调用两次removeAttribute,或者创建你自己的接受多个参数的辅助函数
标签: javascript nodes