如何在选择单选按钮时显示div
?
点击单选按钮的事件是什么?
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<style >
</style>
<script type="text/javascript">
$(".static_class").click(function(){if($(this).val()==="Yes") $("#extra").show("fast"); else $("#extra").hide("fast");});
</script>
</head>
<body>
<input id="r1" type="radio" name="14" value="Yes" class="static_class style1" />
Yes<br />
<input id="r2" type="radio" name="14" value="No" class="static_class style1" /> No<br />
<div id="extra"> <br /><label>If yes, please specify.</label> <input id="email" type="text" class="style" /></div>
</body>
答案 0 :(得分:1)
您的代码似乎没问题,但请确保将代码放在ready
处理程序中:
<script type="text/javascript">
$(function(){
$(".static_class").click(function(){
if($(this).val() === "Yes")
$("#extra").show("fast");
else
$("#extra").hide("fast");
});
});
</script>