易截截图软件、单文件、免安装、纯绿色、仅160KB

使用javascript获取文本框,下拉框,单选框的值并且赋值

1.文本框
1.1 <input type="text" name="test" id="test">
通过var t=document.getElementById("test").value把值赋给变量t,
1.2  当然也可以反过来把已知的变量值赋给文本框,例如:
var m = "5";
document.getElementById("test").value= m;
2.下拉列表框
2.1 <select name="sel" id="sel" onchange="look();">
<option value="1" >11</option>
<option value="2" selected>22</option>
<option value="3">33</option>
</select>
通过var s=document.getElementById("sel").value获取<select>框中选中的值,此处默认选中value="2"的选项,所以赋给变量s 的值是"2",而不是"22",
假如要把<select>中选择的"值"如"3"对应的"文本值"("33")赋给test文本框,可以通过如下方法,
 <script language="javascript">
function look(){
     var se =document.getElementById("sel");  
                 var option=se.getElementsByTagName("option");  
                 var str = "" ;  
                 for(var i=0;i<option.length;++i)  
                 {  
                 if(option[i].selected)  
                 {   
                 document.getElementById("test").value = option[i].text;   
                 }  
          &nb


相关文档:

Javascript中最常用的55个经典技巧

1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="re ......

Javascript中最常用的55个经典技巧

 1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" onc ......

Javascript中最常用的55个经典技巧

 1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table

2. <body onselectstart="return false"> 取消选取、防止复制

3. onpaste="return false&quo ......

Javascript中最常用的55个经典技巧

 1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table

2. <body onselectstart="return false"> 取消选取、防止复制

3. onpaste="return false&quo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号