1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <div id="demo" class="one" title="鼠标经过"></div> 9 <script> 10 var demo = document.getElementById("demo"); 11 alert(demo.getAttribute("title")); 12 demo.setAttribute("class","two"); 13 demo.removeAttribute("title"); 14 15 </script> 16 </body> 17 </html>
元素的属性相关操作element.getAttribute('xxx'),element.setAttribute('xxx','xxx'),element.removeAttribute('xxx')
原文地址:https://www.cnblogs.com/ustc-yy/p/12073839.html
时间: 2024-11-12 21:53:45