首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery未加载wordpress /网页

jquery未加载wordpress /网页
EN

Stack Overflow用户
提问于 2014-12-23 11:13:06
回答 3查看 3.4K关注 0票数 2

我有Wordpress博客页面,它导入了JS文件。JS代码应该在页面加载后启动,但它不起作用。我也不知道原因。

服务器上存在以下文件:http://.。/wp-内容/主题/XXXX/js/script.js在FF控制台中没有错误,

生成的html如下所示:

代码语言:javascript
复制
<html xmlns="http://www.w3.org/1999/xhtml" pl-pl>

<head profile="http://gmpg.org/xfn/11">
    <title>XXXX test &rsaquo; Just another WordPress site</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--
        <meta property="og:title" content="XXXX" />
        <meta property="og:site_name" content="The easiest and fastest way to claim your PAYE tax refund."/>    
      -->

    <link href="http://localhost/wp-content/themes/XXXX/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet" />
    <link href="http://localhost/wp-content/themes/XXXXX/style.css" title="very`plaintxt" rel="stylesheet" media="screen,projection" />

    <link rel="stylesheet" type="text/css" media="print" href="http://localhost/wp-content/themes/XXXXX/print.css" />

    <link rel="alternate" type="application/rss+xml" href="http://localhost/?feed=rss2" title="XXXXX test RSS feed" />
    <link rel="alternate" type="application/rss+xml" href="https://XXXXX.disqus.com/latest.rss" title="XXXXXX test comments RSS feed" />

    <link rel="pingback" href="http://localhost/xmlrpc.php" />
    <script>
        var theChampSiteUrl = 'http://localhost';
    </script>
    <div id="fb-root"></div>
    <script>
        var theChampFBKey = '';
        var theChampFBLang = 'en_US';
    </script>
    <script>
        var theChampForceFBComment = false;
        var theChampFBCommentTitle = '';
        var theChampFBCommentUrl = 'http://localhost/?p=44';
        var theChampFBCommentColor = '';
        var theChampFBCommentNumPosts = '';
        var theChampFBCommentWidth = '100%';
        var theChampFBCommentOrderby = '';
        var theChampFBCommentMobile = '';
        var theChampFBAppID = '';
        var theChampSiteUrl = 'http://localhost';
        var theChampWPCommentingContent = '';
        var theChampFBCommentingContent = '';
        var theChampCommentingLoadFbFirst = 1;
        var theChampCommentingSwitchWpText = 'Switch to default commenting';
        var theChampCommentingSwitchFbText = 'Switch to Facebook commenting';
        var theChampCommentingHandle = false;
    </script>
    <script>
        var theChampSharingAjaxUrl = 'http://localhost/wp-admin/admin-ajax.php';
        var theChampCloseIconPath = 'http://localhost/wp-content/plugins/super-socializer/images/close.png';
        var theChampPluginIconPath = 'http://localhost/wp-content/plugins/super-socializer/images/logo.png';
        var theChampHorizontalSharingCountEnable = 1;
        var theChampVerticalSharingCountEnable = 0;
    </script>
    <link rel='stylesheet' id='open-sans-css' href='//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&#038;subset=latin%2Clatin-ext&#038;ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='dashicons-css' href='http://localhost/wp-includes/css/dashicons.min.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='admin-bar-css' href='http://localhost/wp-includes/css/admin-bar.min.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='core-css' href='http://localhost/wp-content/plugins/simple-subscribe/assets/styleFrontEnd.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='the-champ-frontend-css-css' href='http://localhost/wp-content/plugins/super-socializer/css/front.css?ver=3.4.2' type='text/css' media='all' />
    <link rel='stylesheet' id='really_simple_share_style-css' href='http://localhost/wp-content/plugins/really-simple-facebook-twitter-share-buttons/style.css?ver=4.0.1' type='text/css' media='all' />
    <script type='text/javascript' src='http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1'></script>
    <script type='text/javascript' src='http://localhost/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

    <script type='text/javascript' src='http://localhost/wp-content/themes/XXXXX/js/script.js?ver=4.0.1'></script>

    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/social_login/general.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/facebook/sdk.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/facebook/commenting.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/sharing/sharing.js?ver=3.4.2'></script>
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/xmlrpc.php?rsd" />
    <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/wp-includes/wlwmanifest.xml" />
    <meta name="generator" content="WordPress 4.0.1" />

    <script type="text/javascript">
        <!--
        var a2a_config = a2a_config || {},
            wpa2a = {
                done: false,
                html_done: false,
                script_ready: false,
                script_load: function() {
                    var a = document.createElement('script'),
                        s = document.getElementsByTagName('script')[0];
                    a.type = 'text/javascript';
                    a.async = true;
                    a.src = 'http://static.addtoany.com/menu/page.js';
                    s.parentNode.insertBefore(a, s);
                    wpa2a.script_load = function() {};
                },
                script_onready: function() {
                    if (a2a.type == 'page') {
                        wpa2a.script_ready = true;
                        if (wpa2a.html_done) wpa2a.init();
                    }
                },
                init: function() {
                    for (var i = 0, el, target, targets = wpa2a.targets, length = targets.length; i < length; i++) {
                        el = document.getElementById('wpa2a_' + (i + 1));
                        target = targets[i];
                        a2a_config.linkname = target.title;
                        a2a_config.linkurl = target.url;
                        if (el) {
                            a2a.init('page', {
                                target: el
                            });
                            el.id = '';
                        }
                        wpa2a.done = true;
                    }
                    wpa2a.targets = [];
                }
            };
        a2a_config.tracking_callback = ['ready', wpa2a.script_onready];
        a2a_config.onclick = 1;
        a2a_config.show_title = 1;
        //-->
    </script>
    <script type="text/javascript">
        //<![CDATA[

        ! function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (!d.getElementById(id)) {
                js = d.createElement(s);
                js.id = id;
                js.src = "https://platform.twitter.com/widgets.js";
                fjs.parentNode.insertBefore(js, fjs);
            }
        }(document, "script", "twitter-wjs");

        //]]>
    </script>
    <style type="text/css" media="all">
        /*<![CDATA[*/
        /* CSS inserted by theme options */

        body {
            font-family: 'times new roman', times, serif;
            font-size: 90%;
        }
        body div#container {
            float: left;
            margin: 0 -200px 2em 0;
        }
        body div#content {
            margin: 3em 200px 0 0;
        }
        body div.sidebar {
            float: right;
        }
        body div#content div.hentry {
            text-align: left;
        }
        body div#content h2,
        div#content h3,
        div#content h4,
        div#content h5,
        div#content h6 {
            font-family: arial, helvetica, sans-serif;
        }
        body div#wrapper {
            max-width: 55em;
            min-width: 35em;
            width: 80%;
        }
        body div.sidebar {
            text-align: center;
        }
        /*]]>*/
    </style>
    <style type="text/css">
        .recentcomments a {
            display: inline !important;
            padding: 0 !important;
            margin: 0 !important;
        }
    </style>
    <style type="text/css" media="print">
        #wpadminbar {
            display: none;
        }
    </style>
    <style type="text/css" media="screen">
        html {
            margin-top: 32px !important;
        }
        * html body {
            margin-top: 32px !important;
        }
        @media screen and ( max-width: 782px) {
            html {
                margin-top: 46px !important;
            }
            * html body {
                margin-top: 46px !important;
            }
        }
    </style>
</head>

JS文件:

代码语言:javascript
复制
$(function () {
    alert("aaa");
    /*
    $('#elp_txt_email').addClass('form-control');
    $('#elp_txt_button').addClass('hide');    
    */
});
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-12-23 11:17:42

试试这个:

您可以将javascript包装在一个自调用函数中,然后将jQuery作为参数传递给它,使用$作为局部变量名。例如:

代码语言:javascript
复制
(function($) {
   $(document).ready(function(){
      alert('aaa');
   });
}(jQuery));

jQuery库与WordPress一起被设置为noConflict()模式。这是为了防止WordPress可以链接的其他WordPress库的兼容性问题。

noConflict()模式中,jQuery的全局$快捷方式不可用。

票数 8
EN

Stack Overflow用户

发布于 2014-12-23 11:24:51

实际上,这应该是可行的:

代码语言:javascript
复制
jQuery(document).ready(function(){
   alert('aaa');
});
票数 1
EN

Stack Overflow用户

发布于 2015-01-09 16:42:44

不确定它是否与这个问题有关,但我经常遇到这个问题,所以在这个背景下记录它是个好主意.

在我的例子中,问题是Ajax表单处理程序没有在表单提交之后被调用。相反,它将直接分支到表单中给出的“action”参数。

基本问题是由于wordpress中重复切换了WYSIWYG和HTML编辑器,不知怎么的,ajax表单提交处理程序通过插入![CDATA[ )自动注释掉了。

解决方案是在编辑wordpress帖子时禁用WYSIWYG并删除![CDATA[关键字在脚本.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27619207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档