温馨提示×

HTML的removeAttribute()方法怎么用

小亿
136
2023-09-05 01:08:26
栏目: 编程语言
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

HTML的removeAttribute()方法用于从指定元素中移除属性。

使用方法如下:

element.removeAttribute(attributeName);

其中,element是要操作的元素,attributeName是要移除的属性名。

示例:

<button id="myButton" disabled>点击我</button>
<script>
var button = document.getElementById("myButton");
button.removeAttribute("disabled");
</script>

运行以上代码后,disabled属性将被移除,按钮将变为可点击状态。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

0