【问题标题】:Uncaught TypeError: Cannot read property 'msie' of undefined in WP 5.5未捕获的类型错误:无法读取 WP 5.5 中未定义的属性“msie”
【发布时间】:2020-12-15 18:15:40
【问题描述】:

我有更新到 5.5 版的 WordPress 网站

现在我得到错误:

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/

通过将其添加到我使用的模板的 header.php 中:

<!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 wordpress wordpress-theming wordpress-5.5


    【解决方案1】:

    我最好的猜测是 jQuery 被添加到您网站的页脚,而不是页眉中。

    理想情况下,您可以在您的主题中创建一个 javascript 文件,您可以将其包含并指定它依赖于 jQuery;这样,您可以确定您的代码将始终在 jQuery 之后加载,无论是在页眉还是页脚中加载。

    1. 因此,将标签之间的所有内容放在主题中的单独文件中:我们称之为“scripts.js”

    2. 在你的主题的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

    【讨论】:

      猜你喜欢
      • 2016-09-27
      • 1970-01-01
      • 2013-01-25
      • 2013-02-02
      • 2015-08-01
      • 2017-10-20
      • 2023-04-01
      • 2021-12-22
      • 2015-01-06
      相关资源
      最近更新 更多