0

このスクリプトリンクの JQ の代替案を見つけて、ID の代わりにクラスを使用したいという問題を確認しようとしています。彼ら。それを機能させる方法はありますか?

function toggle(matchingAttribute) {
    // optain all div elements in the page
    var divArray = document.getElementsByTagName("div");
      for(i=divArray.length-1; i>=0; i--) {  // for each div
      if(divArray[i].id.match("_"+matchingAttribute+"_")) {
        if(divArray[i].style.display != 'none') {
          divArray[i].style.display = 'none';
        }
        else {
          divArray[i].style.display = '';
        }
      }
    }
  }  // end function toggle()
4

2 に答える 2

3

これを試して

$('.chk').click(function(){
    var className = $(this).attr('data-class');
    if ($(this).is(':checked'))
    {
        $('.'+className+'').show();
    }
    else
    {
        $('.'+className+'').hide();
    }
});

フィドル

于 2013-07-19T12:55:55.863 に答える