gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:11:27 24 4
gpt4 key购买 nike

我在过滤器中使用了一个函数来检查显示模式是否为 block ,但它不起作用。

这是我的代码:

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

谢谢。

最佳答案

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

Uncaught TypeError: this.css is not a function

您需要使用 jQuery 对象,因为您要在其上调用 jQuery 方法:

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

Demo

关于javascript - 为什么我的 jQuery 过滤器函数中的测试没有按预期工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58631577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com