html元素: <div id="box"> <ul id="ul"> <li>第一个</li> <li id="one" data-name="myattr">第二个</li> <li>第三个</li> </ul> </div>
//getAttribute:获取行内属性的值;
//setAttribute:设置行内属性的值;
// removeAttribute:删除行内属性的值;var one = document.getElementById("one");console.log(one.getAttribute("data-name")); //myattrone.setAttribute("class","two"); //<li id="one" data-name="myattr" class="two">第二个</li>one.removeAttribute("id") //<li data-name="myattr" class="two">第二个</li>
getAttribute、setAttribute 、 removeAttribute
最新推荐文章于 2022-09-22 11:50:53 发布
本文介绍如何使用JavaScript操作HTML元素的属性,包括获取、设置及删除属性的方法。通过具体实例展示了getAttribute()、setAttribute()和removeAttribute()函数的应用。
757

被折叠的 条评论
为什么被折叠?



