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">单击按钮设置H1的class属性为“democlass”</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var h=document.getElementsByTagName("H1")[0]; var typ=document.createAttribute("class"); typ.nodeValue="democlass"; h.attributes.setNamedItem(typ); } </script> </body> </html>
运行结果