jQuery/Javascript-单击复选框时提交表单 [英] jQuery / Javascript - submit form when checkbox is clicked

查看:134
本文介绍了jQuery/Javascript-单击复选框时提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我在其中显示表单数据库的结果,并且有用于过滤结果的复选框.问题是我不想使用提交"按钮,因为我想让用户仅单击复选框以获取所需的结果.那么,如果没有选中提交按钮的复选框被选中,是否仍可以使用javascript或jquery提交表单?如果您在购物网站上看到,则没有提交按钮,只有复选框.谢谢

I have a page where I display results form database and there are checkboxs which filter ther results. The problem is that I don't want to use submit button because I would like to let the user only click on the checkboxes to get the desired results. So is there anyway using javascript or jquery to submit a form when checkbox is checked with no submit button? if you see on shopping sites there are no submit buttons just the checkboxes..Like that. thanks

<form>
<input type="checkbox" name="size" > Size
</form>

这是PHP

<?php if (isset($_POST["size"])){
  //do something
?>

推荐答案

<form id="form" method="post" action="">
    <input type="checkbox" name="checkbox" class="checkbox"/>
    </form> 
    <script type="text/javascript">  
        $(function(){
         $('.checkbox').on('change',function(){
            $('#form').submit();
            });
        });
    </script>

OR

<form id="form" method="post" action="">
<input type="checkbox" onchange="$('#form').submit();"  name="checkbox" class="checkbox"/>
</form>

这篇关于jQuery/Javascript-单击复选框时提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆