JQuery判断radio是否选中,获取选中值



JQuery判断radio是否选中,获取选中值

/*—————————JQuery判断radio是否选中,获取选中值———————————-*/

其他对radio操作功能,以后在添加。直接上代码,别忘记引用JQuery包

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>JQuery radio</title>
<script type=”text/javascript” language=”javascript” src=”JavaScript/jquery-1.6.1.min.js” ></script>
<script type=”text/javascript” language=”javascript”>
/*——判断radio是否有选中,获取选中的值——–*/
$(function(){
$(“#btnSubmit”).click(function(){
var val=$(‘input:radio[name="sex"]:checked’).val();
if(val==null){
alert(“什么也没选中!”);
return false;
}
else{
alert(val);
}
var list= $(‘input:radio[name="list"]:checked’).val();
if(list==null){
alert(“请选中一个!”);
return false;
}
else{
alert(list);
}
});
});
</script>
</head>

<body>
<form id=”form1″ >
<input type=”radio” name=”sex” value=”男” />男
<input type=”radio” name=”sex” value=”女” />女
<br />
<input type=”radio” name=”list” value=”十分满意” />十分满意
<input type=”radio” name=”list” value=”满意” />满意
<input type=”radio” name=”list” value=”不满意” />不满意
<input type=”radio” name=”list” value=”非常差” />非常差
<br />
<input type=”submit” value=”submit” id=”btnSubmit” />
</form>
</body>
</html>

分类: JQuery
标签: JQUERY.RADIO
绿色通道: 好文要顶 关注我 收藏该文与我联系
Xia.CJ
关注 – 10
粉丝 – 9
+加关注
4 0
(请您对文章做出评价)
« 上一篇:判断一个字符串是否在一个数组中
» 下一篇:IE6,IE7下按钮(BUTTON)变宽
posted @ 2011-06-29 09:58 Xia.CJ 阅读(140564) 评论(3) 编辑 收藏

评论列表

#1楼[楼主] 2012-07-16 16:08 Xia.CJ
或者是这样也是可以获取到radio 选中状态
1
var boolCheck=$(‘input:radio[name="sex"]‘).is(“:checked”);
支持(2)反对(0)

#2楼 2013-08-15 16:55 newjoin
var boolCheck=$(‘input:radio[name="sex"]‘).is(“:checked”); 比较好
支持(0)反对(0)


#3楼[楼主] 2013-08-15 17:15 Xia.CJ
@newjoin
是的,比较简洁。

 

jquery 获取radio的选中事件,radio默认选中时,显示其中一行tr,选中另外一个radio时,显示不同的tr记录
2013-09-10 21:121453624811 | 分类:JavaScript | 浏览18624次
<table>
<tr>
<td width=”140″ class=”label”>
定价类型:
</td>
<td>
<input type=”radio” name=”price_type” checked=”checked”
id=”price_type1″ value=”1″ />
普通类型
<input type=”radio” name=”price_type”
id=”price_type2″ value=”1″ />
特殊类型
</td>
</tr>
<tr id=”sellInfo1″ style=”display:none;”>
<TD>123</TD>
</tr>
<tr id=”sellInfo2″ style=”display:none;”>
<td>111</td>
</tr>
</table>
分享到:
2013-09-10 21:54 知识大富翁,挑战答题赢iPhone!提问者采纳
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script type=”text/javascript” src=”jquery-1.9.1.min.js”></script>
<script type=”text/javascript”>
$(function(){
showCont();
$(“input[name=price_type]“).click(function(){
showCont();
});
});
function showCont(){
switch($(“input[name=price_type]:checked”).attr(“id”)){
case “price_type1″:
//alert(“one”);
$(“#sellInfo2″).hide();
$(“#sellInfo1″).show();
break;
case “price_type2″:
$(“#sellInfo1″).hide();
$(“#sellInfo2″).show();
break;
default:
break;
}
}
</script>
提问者评价
真心感谢大神,刚刚接触Jquery

 

div隐藏和显示
2008-11-25 10:11beyond_lbl | 分类:Html/Css | 浏览154226次
点击按扭后显示DIV,当然这个DIV 就显示在按扭旁边,当鼠标移动到DIV上时无变化,当鼠标移出DIV的时候,让DIV隐藏,怎么弄啊!
分享到:
2008-11-25 10:26 知识大富翁,挑战答题赢iPhone!提问者采纳
比较简单的实现.style.display就是控制层隐藏或显示的属性.
<html>
<body>
<script>

function show(){
document.getElementById(“div”).style.display=”";
//alert(document.getElementById(“div”).style.display)
}
function hidden(){
document.getElementById(“div”).style.display=”none”;
//alert(document.getElementById(“div”).style.display)
}
</script>
<BODY>
<input name=”name” type=”button” onClick=”show();” value=”显示”>
<div id=”div” style=”display: none” onMouseout=”hidden();”>
show it
</div>
</BODY>
</HTML>