当前位置:编程学习 > JS >>

js asp.net判断单选按钮是否被选中几种方法

网页特效 asp教程.net判断单选按钮是否被选中几种方法
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.zzzyk.com/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>网页特效 asp.net教程判断单选按钮是否被选中几种方法</title>

<script language="网页特效">
function  yanzheng(){
  var thecheckboxinputs=document.getelementsbyname('gender');
  for(var i=0;i<thecheckboxinputs.length;i++)  
  {  
   if(thecheckboxinputs[i].checked)
     return true;
  }
  alert('您还没有选中其中的一项'); 
  return false;
}
</script>

</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <label>
  <input type="radio" name="gender" id="radio" value="radio" />男
  </label>
  <label>
  <input type="radio" name="gender" id="radio2" value="radio2" />女
  </label>
  <label>
  <input type="submit" name="submit" value="提交"  onclick="return yanzheng();"/>
  </label>
</form>

</body>
</html>

//asp.net

this.radiobuttonlist.items[0].selected==true;

//

<script> 
  function  check() 
  { 
  for(i=0;i <document.form1.r1.length;i++) 
  if(document.form1.r1[i].checked) 
  {alert(document.form1.r1[i].value);return;} 
  } 
</script> 


  <form  name=form1> 
  <input  type=radio  name=r1  value=1> 
  <input  type=radio  name=r1  value=2> 
  <input  type=radio  name=r1  value=3> 
  <input  type=button  onclick=check()> 
  </form>

 

补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,