[英]Allow only one radio button checked in two forms
I have two forms with one radio button for each form. 我有两种形式,每种形式都有一个单选按钮。 How can I fix so that only one radio button can be checked at a time when multiple forms are involved?
如何解决,以便在涉及多个表单时一次只能检查一个单选按钮?
Here are the essential parts of the two forms: 这是两种形式的基本组成部分:
<form name="form1" action="http://www.my-site.com/go-here.php" method="post">
<input type="radio" name="payment" value="radio1" checked="checked" /> Use form1
</form>
<form name="form2" action="http://www.my-site.com/instead-go-here.php" method="post">
<input type="radio" name="payment" value="radio2" /> Use form2
</form>
HTML: HTML:
<form name="form1" action="http://www.my-site.com/go-here.php" method="post">
<input type="radio" name="payment" value="radio1" /> Use form1
</form>
<form name="form2" action="http://www.my-site.com/instead-go-here.php" method="post">
<input type="radio" name="payment" value="radio2" /> Use form2
</form>
JavaScript: JavaScript的:
$("[name=payment]").on("click",function(){
$("[name=payment]").prop('checked', false)
$(this).prop('checked', true)
});
Fiddle: http://jsfiddle.net/44mycngy/ 小提琴: http : //jsfiddle.net/44mycngy/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.