个性化阅读
专注于IT技术分析

jQuery ajax打破了我的Divi主题。我如何解决它?

点击下载

我目前在一个项目中, 我的脚本将架构代码添加到导航中。 jQuery代码确实有效。

但是, 当我添加ajax.googleapis.com的链接时, 它会破坏所有其他Divi样式的脚本。我将不胜感激!请在下面查看我的编码。我有一个儿童主题, 代码存储在functions.php文件中。

我正在使用的主题构建器是Div。

<?php


function load_js()
{

    if(!is_admin())
   { 
    echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>';

      echo '<script type="text/javascript">
jQuery( document ).ready(function(){

    // Put itemscope and itemtype into navigation ul
    $("nav ul").attr("itemscope", "").attr("itemtype", "http://www.schema.org/SiteNavigationElement");
    // put itemprop in lis
    $("nav ul li").attr("itemprop", "name");
    //put itemprop url in anchors
    $("nav ul li a").attr("itemprop", "url");

}); 

 </script>';
   }


}

add_action( 'wp_footer', 'load_js');

#1


经过深思熟虑并致力于其他项目, 我已经完成并解决了这个问题。

问题在于, 用于引入ajax jquery库的脚本已加载到而不是中。因此, 我做了一些简单的更改, 你可以在下面查看以查看修复。

    <?php


    function load_js()
    {

        if(!is_admin())
       { 

          echo '<script type="text/javascript">
    $( document ).ready(function(){

        // Put itemscope and itemtype into navigation ul
        $("nav ul").attr("itemscope", "").attr("itemtype", "http://www.schema.org/SiteNavigationElement");
        // put itemprop in lis
        $("nav ul li").attr("itemprop", "name");
        //put itemprop url in anchors
        $("nav ul li a").attr("itemprop", "url");

    });  
</script>';
       }


    }

add_action( 'wp_footer', 'load_js');

// load ajax jquery for schema nav
function ajax_jquery()
{
    if(!is_admin())
    {
        echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>';
    }
}
add_action( 'et_head_meta', 'ajax_jquery');

谢谢大家的帮助!

赞(0)
未经允许不得转载:srcmini » jQuery ajax打破了我的Divi主题。我如何解决它?

评论 抢沙发

评论前必须登录!