如何解决未捕获的TypeError:无法读取WP 5.5中未定义的属性“ msie”
我有WordPress网站,我已将其更新到版本5.5
现在我得到了错误:
Uncaught TypeError: Cannot read property 'msie' of undefined
at jquery.tools18.min.js?ver=10.2.2:281
at jquery.tools18.min.js?ver=10.2.2:358
(index):738 Uncaught TypeError: $(...).live is not a function
at HTMLDocument.<anonymous> ((index):738)
at i (jquery.js?ver=1.12.4-wp:2)
at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4-wp:2)
at Function.ready (jquery.js?ver=1.12.4-wp:2)
at HTMLDocument.J (jquery.js?ver=1.12.4-wp:2)
我尝试应用此修复程序:
https://bootstrapcreative.com/uncaught-typeerror-cannot-read-property-msie-of-undefined/
<!doctype html>
<html <?phP Language_attributes(); ?>>
<head>
<Meta charset="<?PHP bloginfo( 'charset' ); ?>">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="profile" href="https://gmpg.org/xfn/11" />
<?PHP wp_head(); ?>
<script>
jQuery.browser = {};
(function () {
jQuery.browser.msie = false;
jQuery.browser.version = 0;
if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
jQuery.browser.msie = true;
jQuery.browser.version = RegExp.$1;
}
})();
</script>
</head>
但是它不起作用。我犯了同样的错误。你知道我该如何解决这个问题?
解决方法
我最好的猜测是jQuery被添加到您网站的页脚中,而不是页眉中。
理想情况下,您将在主题中创建一个javascript文件,您可以包含它并指定它依赖jQuery;这样,您可以确定您的代码将始终在 jQuery之后加载,无论是在页眉还是页脚中加载。
-
因此,将标记之间的所有内容放在主题的单独文件中:我们将其称为“ scripts.js”
-
在您主题的functions.php文件中,您希望将该脚本作为jQuery的依赖项进行加载:
add_action('wp_enqueue_scripts','my_theme_name_enqueue_scripts'); 函数my_theme_name_enqueue_scripts(){ wp_enqueue_script('my-theme-name-js',get_template_directory_uri()。'/scripts.js',array('jquery')); }
wp_enqueue_script
函数调用的第三个参数是您依赖的其他脚本数组。
要获取WordPress可提供的脚本句柄/名称的完整列表,see here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。