私は7つのチェックボックスにすべて異なるIDを使用しています。 div内のデータメソッドが含まれているIDの通信者。チェックボックスをクリックすると、対応するID以外のすべてのdivが非表示になります。jQueryはチェックボックスに複数の値を表示しない
この瞬間に動作します!しかし、複数のチェックボックスを選択すると、すべてのdivが消えます。私はそれがすべて選択されたID年代に耳を傾けるように、私はこのスクリプトを最適化する方法だろ
<script type="text/javascript">
jQuery('.filter_methode input').change(function()
{
jQuery('.featured-item-container').show();
jQuery('input').each(function()
{
var Checked;
if(Checked = jQuery(this).attr('checked'))
{
jQuery(".featured-item-container:not([data-methode='" + this.id + "'])").hide();
};
});
});
</script>
:
は、これが私のjavascriptのです。私はそれが唯一のデータ-Methodeの= "methode_1" とdivを私に示していmethode_1 IDでのチェックボックスをクリックしますので
<div class="filter_methode">
<label><input type="checkbox" name="methode_1" id="methode_1" />
Methode 1</label>
<label><input type="checkbox" name="methode_2" id="methode_2" />
Methode 2</label>
<label><input type="checkbox" name="methode_3" id="methode_3" />
Methode 3</label>
<label><input type="checkbox" name="methode_4" id="methode_4" />
Methode 4</label>
<label><input type="checkbox" name="methode_5" id="methode_5" />
Methode 5</label>
<label><input type="checkbox" name="methode_6" id="methode_6" />
Methode 6</label>
<label><input type="checkbox" name="methode_7" id="methode_7" />
Methode 7</label>
<label><input type="checkbox" name="methode_8" id="methode_8" />
Methode 8</label>
<div class="featured-container col-md-12">
<div class="row">
<div class="featured-item-container" data-methode="methode_1">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_1">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_1">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_3">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_7">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_8">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_2">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_4">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_8">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_5">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_6">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_5">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_1">
Some text and image in here
</div>
<div class="featured-item-container" data-methode="methode_2">
Some text and image in here
</div>
</div>
</div>
:ここで編集
はHTMLですしかし、methode_1とmethode_2のdivを表示する代わりに、methode_2のチェックボックスをクリックすると、すべてのdivが消えます。
あなたのHTMLコードを表示してください。 –
if(Checked == jQuery(this).attr( 'checked')) 'のように' if(Checked = jQuery(this).attr( 'checked')) '' '=='また、 'html'を投稿しても良いです... –