JS基础——属性操作

来源:互联网 发布:人工智能具体应用实例 编辑:程序博客网 时间:2024/06/04 19:40


[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <!doctype html>  
  2. <html>  
  3. <head>  
  4. <meta charset="utf-8">  
  5. <title>JS属性操作1</title>  
  6. <script>  
  7. window.onload = function(){  
  8.     var oText = document.getElementById('text1');  
  9.     var oSel = document.getElementById('select1');  
  10.     var oBtn = document.getElementById('btn1');  
  11.       
  12.     //读操作:获取、找到 【元素.属性名】      
  13.     //alert(oSel.value);  
  14.     //alert(oBtn.value);  
  15.       
  16.     //写操作:“添加”、替换、修改 【元素.属性名 = 新的值】  
  17.     // 字符串连接  
  18.     // oText.value    oSelect.value  
  19.     // '张三' +  '北京'  =>  '刘伟北京'  
  20.     // '张三' + '在' + '北京'     =>  '刘伟在北京'  
  21.     //alert(oText.value + '在' + oSel.value);      
  22.     oBtn.onclick = function(){  
  23.         //oText.value = '123';  
  24.         //oBtn.value = 'button';  
  25.         //oText.value = oSel.value;  
  26.         alert(oText.value + '在' + oSel.value);        
  27.     };  
  28.       
  29.       
  30. };  
  31. </script>  
  32. </head>  
  33.   
  34. <body>  
  35. <input id="text1" type="text" />  
  36. <select id="select1">  
  37.     <option value="北京">北京</option>  
  38.     <option value="上海">上海</option>  
  39.     <option value="杭州">杭州</option>  
  40. </select>  
  41. <input id="btn1" type="button" value="按钮" />  
  42. </body>  
  43. </html> 
0 0
原创粉丝点击