欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js获取单选按钮(radio)组的值来控制tr td

程序员文章站 2022-07-07 19:57:44
...
<script type="text/javascript" src="js/jquery.js"></script>
<script>
function checks(){
    var radios=document.getElementsByName("psam");
    for(var i=0;i<radios.length;i++){
    	//alert($("input[name='psam'][checked]").val()); 
        if(radios[i].checked==true){
            if((radios[i].value)==2){
        	document.getElementById( "psamcodeend").style.display= "inline";
       	 	$("#hidone").val("2"); //给隐藏域赋值
         	}
        }
       if(radios[i].checked==true){
        if((radios[i].value)==1){
		//none是不显示,inline是内联式显示,不换行
            document.getElementById( "psamcodeend").style.display= "none";
            document.getElementById("psamcodeend").value = "";
            $("#hidone").val("1");
        }
       }
    }
}
window.onload = checks ; //页面加载完成时执行一次该js函数。
</script>

-------------------------------------------------------
HTML CODE:
        <tr> 
          <th align="left">PSAM录入方式:</th>
         	<td> <input id="arecord" name="psam" type="radio" value="1" checked onclick="checks()"/>单条录入
         	<input id="records"  name="psam" type="radio" value="2"  onclick="checks()">批量录入</td>
        </tr>
    
    <tr>
      <th align="left">PSAM卡号:</th>
      <td><input name="psamcode" type="text" id="psamcode" size="30" maxlength="21" />
      	<input name="psamcodeend" type="text" id="psamcodeend" size="30" maxlength="21" />
      	<input type="hidden" name="psammodel" id="hidone">
      </td>
    </tr>