0

(#check_all) を追加するまで、私のスクリプトは非常にうまく機能しました。チェックボックスは機能しませんが、個別には正常に機能します。問題が見つかりません、助けてください。

私のスクリプト

<script type="text/javascript">
$(document).ready(function(){

$(".bt").click(function(){
    $(".select_box").hide('fast');
    if ($(this).next('.select_box').is(':visible')){
        $(this).next(".select_box").hide('fast');
    }
    else{
        $(this).next(".select_box").fadeIn('fast');
    }
});
$(document).click(function() {
    $(".select_box").hide();
});
$(".bt,.select_box").click(function(e) {
    e.stopPropagation();  
    return false;                             
});

$('#check_all').click(function(){
    $(this).parents('div:eq(0)').find(':checkbox').attr('checked', this.checked);
}); 
});

</script>

HTML

<a class="bt" href="#">[X]</a>
<div class="select_box" style="display:none;border:1px solid;">
    <input id="check_entite" type="checkbox" />(Select All)<br />
    <input type="checkbox" />1<br />
    <input type="checkbox" />2<br />
</div>
<br><br>
<a class="bt" href="#">[X]</a>
<div class="select_box" style="display:none;border:1px solid;">
    <input id="check_all" type="checkbox" />(Select All)<br />
    <input type="checkbox" />1<br />
    <input type="checkbox" />2<br />
</div>
4

4 に答える 4

0

理由はjsではないと思います。実際にはロジックが複雑すぎるため、再編成する必要があります。これを試すか、ここで結果を確認してください:

<script type="text/javascript">
$(document).ready(function(){

$(".bt").click(function(){
    $(".select_box").hide('fast');
    if ($(this).next('.select_box').is(':visible')){
        $(this).next(".select_box").hide('fast');
    }
    else{
        $(this).next(".select_box").fadeIn('fast');
    }
});
$(document).click(function() {
    $(".select_box").hide();
});
$(".bt,.select_box").click(function(e) {
    e.stopPropagation();  
    return false;                             
});

$('#check_all').click(function(){
    $(this).parents('div:eq(0)').find(':checkbox').attr('checked', this.checked);
      e.stopPropagation();  
    return false; 
}); 
});

于 2013-03-18T12:12:14.807 に答える
0

これを参照してください:サンプル

$(document).ready(function () {

  $(".bt").click(function (e) {
      $(".select_box").hide('fast');
      if ($(this).next('.select_box').is(':visible')) {
          $(this).next(".select_box").hide('fast');
      } else {
          $(this).next(".select_box").fadeIn('fast');
      }
      e.stopPropagation();
   });
  $(document).click(function (e) {
      $(".select_box").hide();
  });
  $('.select_box').click(function (e) {
      e.stopPropagation();
  });
  $('#check_all,#check_entite').click(function (e) {
      $(this).siblings(':checkbox').prop('checked', this.checked);
      e.stopPropagation();
  });
});
于 2013-03-18T12:04:03.117 に答える
0

あなたは何を達成しようとしていますか:

$(".bt,.select_box").click(function(e) {
    e.stopPropagation();  
    return false;                             
});

?

これは動作中のバージョンです: JSFiddle

$(document).ready(function () {

    $(".bt").click(function (e) {
        $(".select_box").hide('fast');
        if ($(this).next('.select_box').is(':visible')) {
            $(this).next(".select_box").hide('fast');
        } else {
            $(this).next(".select_box").fadeIn('fast');
        }
        return false;
    });
    $(document).click(function () {
        $(".select_box").hide();
    });

    $('.check_all').click(function () {
        var checked = ($(this).prop('checked'));
        $(this).parent('div').find(':checkbox').prop('checked', checked);
    });
});
于 2013-03-18T12:23:40.817 に答える
0
$(this).closest('div').find(':checkbox').attr('checked', this.checked);
于 2013-03-18T11:46:59.007 に答える