(030)javascript_dom_setAttribute

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <title>DOM</title>
 6     <script type="text/javascript">
 7 
 8         window.onload = function() {
 9 
10             var inputTextNode = document.getElementById("mytext");
11             
12             //改变文本框文本属性
13             inputTextNode.value = "3";
14 
15             inputTextNode["value"] = "6";
16 
17             inputTextNode.setAttribute("value","test");//Chrome不起作用???
18         };
19         
20     </script>
21 </head>
22 
23 <body>
24     <input id="mytext" type="text"/>
25 </body>
26 </html>

 

posted @ 2014-02-06 10:17  雪中飞雁  阅读(95)  评论(0)    收藏  举报