[英]How to swap buttons (with jQuery) based on radio button checked or not
[英]How to select latest checked radio button in multiple radio buttons with jQuery
在这个中,如何用jquery选择最新的单选按钮是由用户选择的
<form id = "myform">
<h3>Time to work?</h3>
<p>
<input type="radio" name="work" value="Hourly" />
<input type="radio" name="work" value="Daily" />
<input type="radio" name="work" value="Weekly" />
</p>
<h3>Your Age?</h3>
<p>
<input type="radio" name="age" value="old" />
<input type="radio" name="age" value="young" />
<input type="radio" name="age" value="child" />
</p>
</form>
我试过了
$('input:checked', '#myform').val();
和
$('input[type='radio']:checked', '#myform').val();
但它始终选择第一个问题的唯一值! 任何帮助?
尝试为每个单选按钮添加“单击”侦听器。 然后只需将值存储在变量中。
尝试这个 :
<script type="text/javascript"> jQuery("input[type=radio]").click(function(){ alert(jQuery(this).val()); }); </script>
好吧,你有一些单引号和双引号的语法错误,你可能会注意到代码中的语法高亮。 你还需要使用name属性,而不仅仅是input
:
$('input[name="age"]:checked').val()
$('input[name=radioName]:checked', '#myForm').val()
应该为您提供所选的单选按钮值。 另外$('input[name=myradiobutton]:radio:checked')
应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.