单选按钮选择
问题描述:
ID谨在此提醒当我点击他们每个人的单选按钮的名称。但条件中只有一个单选按钮。请帮忙。在jQuery的即时通讯新单选按钮选择
<html>
<head>
<style type="text/css">
#container{
width:500px;
height:300px;
background-color:#F9F9F9;;
}
</style>
<script type="text/javascript" src="jquery-1.6.1.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
$("input[@name=testGroup]:checked").click(function(){
if($(this).val() == "pizza"){
alert("pizza");
}
else if($(this).val()== "cake"){
alert("cake");
}
});
});
</script>
</head>
<body>
<input type="radio" class="rad_but" name="food" value="pizza">Pizza</input>
<input type="radio" class="rad_but" name="food" value="cake">Cake</input>
<input type="radio" class="rad_but" name="food" value="others">Others</input>
<div id="container">
</div>
</body>
</html>
每次点击他们每个人只有一个单选按钮警报的值。请帮助
答
这是你需要什么? DEMO
$("input[name='food']").change(function() {
if($(this).val() == "pizza"){
alert("pizza");
}
else if($(this).val()== "cake"){
alert("cake");
}
else if($(this).val()== "others"){
alert("others");
}
});
究竟..笏确实会改变吗? – user978064 2012-04-28 16:00:55
您可以检查它从这里http://api.jquery.com/change/ – coder 2012-04-28 16:01:53
究竟做什么,我简化你的答案在这里:http://jsfiddle.net/YWHM5/1/ – 2012-04-28 16:03:39