繁体   English   中英

为什么我的 jQuery 过滤器 function 中的测试没有按预期工作?

[英]Why isn't the test in my jQuery filter function working as expected?

我在过滤器中使用了 function 来检查显示模式是否为块但它不起作用。

这是我的代码:

$("#wrap_element").find("*").filter(function(){
    return this.css("display")==="block";
}).css("background-color","red");

谢谢。

您有一个提示问题的控制台错误:

未捕获的类型错误:this.css 不是 function

您需要使用 jQuery object 因为您在其上调用 jQuery 方法:

return $(this).css("display")==="block";
// ----^^----^

演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM