我创建它没有问题,我的问题是:当我尝试检测空返回时。我准备了 jsFiddle 进行检查,点击“B”来寻找我想要的东西,但是用一种可靠的方式。
基本上我正在尝试用聪明的方式检查结果是否为空?
jQuery:
var triggers = $('ul.alphabet li a');
var filters = $('ul.medical_dictionary li strong');
triggers.click(function() {
var takeLetter = $(this).text();;
filters.parent().hide();
filters.each(function(i) {
var compareFirstLetter = $(this).text().substr(0,1);
if ( compareFirstLetter == takeLetter ) {
$(this).parent().fadeIn(222);
}
//problem on detecting empty one. Press 'B' for example.
//i can reach manually but this way is useless
if (takeLetter ==='B') {console.log('There is no result.');}
});
});
</p>
html:
<ul class="alphabet">
<li><a>A</a></li>
<li><a>B</a></li>
<li><a>C</a></li>
<li><a>...</a></li>
</ul>
<ul class="medical_dictionary">
<li><strong>Abdominoplasti</strong>: Lorem ipsum.</li>
<li><strong>Absans</strong>: Lorem ipsum.</li>
<li><strong>Abse</strong>: Lorem ipsum.</li>
<li><strong>....</strong>: Lorem ipsum.</li>
</ul>