我有两个表单,每个表单都有一个单选按钮。如何修复以便在涉及多个表单时只能检查一个单选按钮?
以下是两种形式的基本部分:
<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>
答案 0 :(得分:1)
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的:
$("[name=payment]").on("click",function(){
$("[name=payment]").prop('checked', false)
$(this).prop('checked', true)
});