2014-11-24 102 views
0

我有两种形式,每种形式都有一个单选按钮。我该如何修复,以便在涉及多个表格的时候只能检查一个单选按钮?只允许一个单选按钮检查两种形式

这里有两种形式的基本部分:

<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

唐吨你有其他数据发送给a ction url这个wat没有任何意义。 – 2014-11-24 13:47:11

+0

你有没有尝试过任何东西? – 2014-11-24 13:52:49

+0

它也试图达到什么目的? – 2014-11-24 13:55:53

回答

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) 

}); 

小提琴:http://jsfiddle.net/44mycngy/

+0

工程就像一个魅力!谢谢mgibala :) – Carl 2014-11-24 14:14:36