如果格式sAddToBasket
中的广播被检查,如何提交表单radioform
?
<form name="radioform" method="post" action="something1.php">
<input type="radio" onchange="this.form.submit();" class="option--input" id="radio1" name="radio" value="">
<input type="radio" onchange="this.form.submit();" class="option--input" id="radio2" name="radio" value="">
</form>
<form name="sAddToBasket" method="post" action="something2.php">
<input type="hidden" name="option1" value="value1"/>
<input type="hidden" name="option2" value="value2"/>
</form>
答案 0 :(得分:1)
我会摆脱DOM中的JS(你的onchange=...
)并做这样的事情:
$(document).ready( function() {
$("form[name=radioform] input").on("change", function() {
$("form[name=sAddtoBasket").submit();
}
});
答案 1 :(得分:0)
你可以试试这样的事情
<form name="radioform" method="post" action="something1.php"> <input type="radio" onchange="document.getElementById('sAddToBasket').submit();" class="option--input" id="radio1" name="radio" value=""> <input type="radio" onchange="document.getElementById('sAddToBasket').submit();" class="option--input" id="radio2" name="radio" value=""> </form>
<form id='sAddToBasket' name="sAddToBasket" method="post" action="something2.php"> <input type="hidden" name="option1" value="value1"/> <input type="hidden" name="option2" value="value2"/>
</form>
答案 2 :(得分:0)
onchange你可以像下面这样调用js函数。
<input type="radio" onchange="formSubmit(this)" class="option--input" id="radio1" name="radio" value="">
<form id="sAddToBasket">
</form>
<script>
function formSubmit(radioObj){
if(radioObj.checked){
document.getElementById("sAddToBasket").submit();
}
}
</script>
答案 3 :(得分:0)
只需在单选按钮中添加一个类。
<form name="radioform" method="post" action="something1.php">
<input type="radio" class="option--input subForm" id="radio1" name="radio" value="">
<input type="radio" class="option--input subForm" id="radio2" name="radio" value="">
</form>
并在脚本上使用:
$(function(){
$('.subForm').click(function(){
if($(this).is(":checked")
$('form[name=sAddtoBasket]').submit();
})
})