单击表单上的JQuery无线电输入提交

时间:2014-12-12 18:47:52

标签: javascript jquery html wordpress forms

我选择了一个单选按钮时,我想要提交一个表单。我已经尝试了一些方法来使它工作,但事实并非如此。

我的表格是这样的(只有一个无线电选项,但最初的选项有20个选项):

<form action="http://spartanas.com.br/novo/wp-comments-post.php" method="post" id="votoscommentform" class="comment-form">
<div class="anuncio vitrine">
 <a href="http://spartanas.com.br/novo/ninasalvattori/">
   <div style="position: absolute; width: 172px; height: 285px;" class="fphover">&nbsp;</div>
   <img src="http://spartanas.com.br/novo/wp-content/plugins/nextcellent-gallery-nextgen-legacy/nggshow.php?pid=982" style="width:172px;height:285px">
 </a>
 <div class="infos">Nina Salvattori<br>Hotéis e Motéis</div>
 <div style="text-align:center"><strong>1 Voto</strong><br>
 <p><input onchange="this.form.submit();" value="6019" id="6019" name="comment" type="radio"><label for="6019">Votar</label></p></div></div>
<p class="form-submit">
<input name="submit" id="votarcomentform" value="Votar" type="submit">
<input name="comment_post_ID" value="6183" id="comment_post_ID" type="hidden">
<input name="comment_parent" id="comment_parent" value="0" type="hidden">
</p>
<input id="_wp_unfiltered_html_comment_disabled" name="_wp_unfiltered_html_comment" value="f33d177e03" type="hidden"><script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>
</form>

正如你可以看到这个版本我尝试用onchange事件提交它,但我也尝试过使用JQuery:

<script>
jQuery(document).ready(function($) {
    $('input[type="radio"][name="comment"]').click(function() {
        $(this).closest("form").submit();
    });
}); 
</script>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您可以使用更改活动...

&#13;
&#13;
<script>
jQuery(document).ready(function($) {
    $('input[type="radio"][name="comment"]').change(function() {
        $(this).closest("form").submit();
    });
}); 
</script>
&#13;
&#13;
&#13;