XML DOM setAttribute()
setAttribute(name,value);
name:属性名 value:属性值
例:
查看代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>createTextNode</title> <style type="text/css"> *{margin:0;padding:0;} body{margin:50px;} a{padding:5px 20px;background:#5fa704;font-size:12px;color:white;} </style> <script type="text/javascript"> window.onload = function(){ var a=document.createElement("a"); a.setAttribute("href","http://www.baidu.com"); var t = document.createTextNode("找回您遗失的好友,点击这里"); a.appendChild(t); document.body.appendChild(a); } </script> </head> <body> </body> </html>
1.createElement创建一个a节点.
2.setAttribute设置a的href属性值.
3.createTextNode创建一个文本节点,并appendChild到a节点.
4.document.body.appenChild(a),添加到body.
啊,自己看到XML DOM的操作这里,感觉这内容有点多,繁琐,慢慢来吧,先在这里做个笔记:D

浙公网安备 33010602011771号