我有一个页面,我在其中显示来自数据库的结果,并且有用于过滤结果的复选框。问题是我不想使用提交按钮,因为我想让用户只需单击复选框即可获得所需的结果。那么在没有提交按钮的情况下选中复选框时,是否仍然使用 javascript 或 jquery 提交表单?如果您在购物网站上看到没有提交按钮,只有复选框……就像那样。谢谢
<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>
或
<form id="form" method="post" action="">
<input type="checkbox" onchange="$('#form').submit();" name="checkbox" class="checkbox"/>
</form>