获取select、radio、checkbox的value值以及文本框值

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> 获取被选中的radio值</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script src="js/jquery-1.7.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function(){
	   $("#test").click(function(){
	       $(":input[type='checkbox']:checked").each(function(){  //获取被选中的checkbox的value值
			                     alert($(this).val());
				})	         
			    var   docTemp=document.thisform.checkbox; 
				for   (i=0;i <docTemp.length;i++){ 
				if(docTemp[i].checked){ 
				strText=docTemp[i].nextSibling.nodeValue;						//  获取被选中的checkbox的文本值
				alert(strText);      
				}
			}				
				alert($(":radio:checked + span").text());								//获取被选中的radio 文本值
				alert($(":input[type='radio']:checked").val());				//获取被选中的radio value值
				alert($("#select_id").val());														// 获取被选中的  select的value值
				alert($("#select_id").find("option:selected").text());		// 获取被选中的  select的文本值
         })
	})
  </script>
 </head>
 <body>
 <form  name="thisform" method="post">
      你爱国吗:    <input type="radio" name="radio1"   class="rd"   id="rd" value="1"/> 
	  <span>a</span>
        <input type="radio" name="radio1"class="rd"  id="tt" value="2" />
       <span>b</span>
        <input type="radio"name="radio1"class="rd"  value="3"/>
       <span>c</span>
		<ul id="options" class="options">
      <li><label for="opA" ><input type="checkbox" name="checkbox" id="opA"  value="1"/>选项A</label></li>
      <li><label for="opB" ><input type="checkbox" name="checkbox" id="opB" value="2" />选项B</label></li>
      <li><label for="opC" ><input type="checkbox" name="checkbox" id="opC"  value="3"/>选项C</label></li>
      <li><label for="opD"  id="op"><input type="checkbox" name="checkbox" id="opD"  value="4"/>选项D</label></li>
    </ul>
	<select  id="select_id">
			<option value="111">aa</option>
			<option value="222">bb</option>
			<option value="333">cc</option>
	</select>
	<input type="button" value="test" id="test"/>
</form>
 </body>
</html>


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值