我想检查用户输入是否与div中的内容匹配,但是当输入不匹配我要显示no match found
但不起作用的任何内容时出现问题
如何将其传递给另一个id,而不是使用父nod
//This is working
$(tageslist).find("h1:not(:Contains(" + filter + "))").parent().slideUp();
//But here i want to show this message in a different div
$(tageslist).find("h1:not(:Contains(" + filter + "))", function(){
$('#notfilter').html('Not found');
});
不工作
答案 0 :(得分:0)
您的代码中存在两个问题:
.find()
方法不接受两个参数。要检查是否有任何内容,请使用.length
属性。.find()
中的过滤器正在搜索您实际需要的内容。只要至少有一个元素不包含您的过滤字符串,即使存在过滤字符串,它也会返回true。要解决这些问题,请使用以下代码:
if ($(tageslist).find("h1:Contains(" + filter + ")").length === 0) {
$('#notfilter').html('Not found');
}