复选框全部勾选,做点什么?

时间:2012-11-27 15:12:52

标签: php jquery html sql

我只是想找到最好的方法来帮助你。

所以我有一个示例SQL数据库:

Sample SQL Database http://i47.tinypic.com/2rhy9ok.jpg

现在,从该数据库中我有一个PHP页面,如果相应的复选框字段中有“1”,则会显示复选框。

Checkboxes http://i50.tinypic.com/20u4cq8.jpg

我现在想做的是:

一旦选中了两个复选框,我想显示一个5秒的计时器或一条消息,这是一种性质,但我如何确定这两个盒子是否都被检查过?

我猜我必须针对整个表运行查询并从我回来的变量开始工作?

3 个答案:

答案 0 :(得分:4)

您可以使用更改活动

var i = 1, interval, timeout;
$('input[type=checkbox]').on('change', function(){

   if ($('input[type=checkbox]').length ==   $('input[type=checkbox]:checked').length) {
       $('div').show();
       interval = window.setInterval(
         function() {
           $('div').text(i++);
         },
         1000
       );
       timeout = window.setTimeout(
         function(){
           document.location = 'http://google.com/';
         },
       5000);
   }
  else {
    window.clearTimeout(timeout);
    window.clearInterval(interval);
    $('div').hide().text('0');
    i = 1;
  }
});

编辑http://jsbin.com/uwofus/11/edit的示例 测试http://jsbin.com/uwofus/11

的示例

答案 1 :(得分:0)

你用jQuery标记了这个,所以我假设你想在浏览器中进行检查,而不是在数据库中。

if ($("input[type='checkbox']:checked").size() == 2) {
   //both boxes are checked
   //display message/start timer here
} else {
   //not all boxes are checked
}

答案 2 :(得分:0)

你可以给你的复选框一个例如mycb,然后计算检查的数字:

$('.mycb').change(function(){

    if($('.mycb').size() == $('.mydb:checked').size())
    {
        // all checkboxes are checked - do something
    }

});
相关问题