-2

I'm just looking for a bit of help on the best way to do this..

So I have a sample SQL Database:

Sample SQL Database

Now from that DB I have a PHP page to show checkboxes ticked if there is a "1" in the corresponding checkbox field.

Checkboxes

What I would now like to do is:

Once both checkboxes are ticked, I would like to display a 5 second timer or a message, something of that nature, but how do I ascertain if the boxes have both been checked?

I'm guessing I would have to run a query against the whole table and work from the variable I get back?

4

3 に答える 3

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を編集する例/http://jsbin.com/uwofus/11 をテストする例を編集

于 2012-11-27T15:20:40.893 に答える
0

これを jQuery でタグ付けしたので、データベースではなくブラウザーでチェックを行いたいと思います。

if ($("input[type='checkbox']:checked").size() == 2) {
   //both boxes are checked
   //display message/start timer here
} else {
   //not all boxes are checked
}
于 2012-11-27T15:19:29.000 に答える
0

チェックボックスにクラスなどを与えてから、チェックされたmycb数を数えることができます:

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

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

});
于 2012-11-27T15:21:20.003 に答える