fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> <style type="text/css"> .democlass{ color:red; } </style> </head> <body> <h1>Hello World</h1> <p id="demo">单击按钮来创建一个“类”属性值“democlass”插入到上面的H1元素。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var h1=document.getElementsByTagName("H1")[0]; var att=document.createAttribute("class"); att.value="democlass"; h1.setAttributeNode(att); } </script> </body> </html>
运行结果