###前提・実現したいこと
・html、CSS、javascriptを用いて、and検索による絞り込み機能を制作。
・絞り込みを行った際に、表示するものが何もない時に「表示できるものがありません」と表示を出したい
###発生している問題・エラーメッセージ
下記ページを参照させていただき、絞り込み自体はできました。
http://jsdo.it/carl_marie/jquery_hide_rows
しかし、表示できるものがないときに「表示できるものがありません」と出す方法がわかりません。
###該当のソースコード
<!-- 絞り込み機能設定 ここから --> <script> $(function (){ var $chkbxFilter_all = $('#all'); $(function(){ var radio = $('input[type="radio"]'); var checked = new Array(); var i; radioChecked(); radio.on('click', function(){ i = radio.index(this); if(checked[i]) { $(this).prop('checked', false); } radioChecked(); }); function radioChecked() { checked = []; radio.each(function() { if($(this).prop('checked')) { checked.push(true); } else { checked.push(false); } }); } }); //チェックボックスがクリックされた時の動作 $(".select_item p input").click(function() { $(this).parent().toggleClass("selected"); $.each($chkbxFilter_tags, function() { if($('#' + this).is(':checked')) { $("#result " + $chkbxFilter_blocks + ":not(." + this + ")").addClass('hidden-not-' + this); $chkbxFilter_all.prop('checked',false).parent().removeClass("selected"); } else if($('#' + this).not(':checked')) { $("#result " + $chkbxFilter_blocks + ":not(." + this + ")").removeClass('hidden-not-' + this); } }); }); }); </script> <!-- 絞込の項目を設定 ここから --> <script> // 絞り込みに使うclassを記述 var $chkbxFilter_tags =['inp01','inp02','inp03,//絞り込み項目グループ1 'chn01','chn02','chn03',//絞り込み項目グループ2 'smp01','smp02','smp03',//絞り込み項目グループ3 ]; // 絞り込み対象の要素を指定 var $chkbxFilter_blocks = ['.product'] </script> <!--絞込の項目を設定 ここまで --> <!--スタイルシートで、非表示にする事で絞込を行う --> <style> #result [class*="hidden-"] {display: none;} </style> <!--絞り込み 選択要素--> <table id="select"> <tr class="filter_tag"> <td>絞り込み項目1</td> <td class="select_item"> <p><input type="checkbox" name="tag" value="項目1-1" id="inp01" class="sort"><label for="inp01">項目1-1</label></p> <p><input type="checkbox" name="tag" value="項目1-2" id="inp02" class="sort"><label for="inp02">項目1-2</label></p> </td> </tr> <tr class="filter_channel"> <td>絞り込み項目2</td> <td class="select_item"> <p><input type="radio" name="channel" value="項目2-1" id="chn01"><label for="chn01">項目2-1</label></p> <p><input type="radio" name="channe2" value="項目2-2" id="chn02"><label for="chn01">項目2-2</label></p> </td> </tr> <tr class="filter_sampling"> <td>絞り込み項目3</td> <td class="select_item"> <p><input type="radio" name="sample" value="項目3-1" id="smp01"><label for="smp01">項目3-1</label></p> <p><input type="radio" name="sample" value="項目3-2" id="smp02"><label for="smp02">項目3-2</label></p> </td> </tr> </table> <!--絞込まれる要素 --> <div class="product inp01 chn01 smp02"> <p>商品1</p> </div><!--/.product--> <div class="product inp01 chn01 smp01"> <p>商品2</p> </div><!--/.product--> <div class="product inp02 chn02 smp02"> <p>商品3</p> </div><!--/.product--> <div class="product inp01 chn02 smp01"> <p>商品4</p> </div><!--/.product--> <div class="product inp02 chn01 chn02"> <p>商品5</p> </div><!--/.product-->
###補足情報
絞り込み機能自体は実現出来ているのですが、「表示できるものがありません」の表示機能の追加方法がわかりません。どなたかヒントでも結構ですのでご教授いただけないでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/05 12:59