javascript - 使用 .has() 时 jQuery 不是函数
问题描述
我有这个简单的 jQuery 代码
function removePreloader() {
jQuery('ul.woocommerce-error').has('li').jQuery("#preloader").css("display", "hidden");
}
它被调用
jQuery('form[name="checkout"]').submit(function(e) {
... // lots of line
setTimeout(removePreloader(), 2000);
}
两个代码块都在里面jQuery(document).ready(function() { ... });
另一个jQuery()
工作正常,只有这个导致问题并显示
未捕获的类型错误:jQuery(...).has(...).jQuery 不是函数
不能用.has
吗?还是有替代品?因为这个wordpress主题使用了很多老插件,所以他们不能接受新版本的jQuery。
谢谢
这是来自的屏幕截图jquery.com
我只是想遵循这个 javascript 并对其进行一些修改,请让我知道如何以正确的方式执行此操作,因为我以前从未使用 javascript 编码
解决方案
您正在使用无效的 jQuery 语句.jQuery...
,我建议if
在检查列表中是否有任何子项时使用该语句,li
例如:
function removePreloader() {
if( jQuery('ul.woocommerce-error li').length ){
jQuery("#preloader").css("display", "none");
}
}
注意 1: display
属性没有hidden
价值,因此您正在搜索none
。
注意2:删除()
函数调用中的,如:
setTimeout(removePreloader, 2000);
推荐阅读
- python - 从另一个目录运行 python 脚本
- c++ - Arduino RTC 每 8 小时减去 1 秒
- bash - 如何从 IntelliJ IDEA 的 bash 设置 SBT 以避免格式化字符被破坏?
- mysql - 查询名称(名字和姓氏)
- python - python unittest模拟嵌套函数
- python - 如何解决 python 3.6 的版本兼容错误
- azure-service-fabric - 有没有办法为不同的无状态服务实例分配一个 int 号?
- javascript - jQuery对话框中有大量数据时滚动条冻结
- php - 在 SQL 数据库上搜索时是否有包含复数词?
- r - 是否可以在 R Shiny 中找到由非矩形画笔选择的数据行?