簡體   English   中英

屬性'$'的對象

[英]Property '$' of object

我有一個Wordpress網站,最終是一個流媒體廣播網站。 在標題我有一個腳本,從我的專用服務器的CP拉動流數據(如聽眾計數和當前播放)..(Centova演員)

我在function.php中注冊了腳本:

這是登記冊

wp_register_script('streaminfo','http://94.23.250.14:2199 / system / streaminfo.js',false,null); wp_enqueue_script('streaminfo');

這是整個jQuery部分供您查看..

/* ------------------------------------

:: INITIATE JQUERY / STYLING

------------------------------------ */

function init_dynscripts() {
    if (!is_admin()) {

        if ( function_exists('bp_is_blog_page')) {
            if (!bp_is_blog_page()) {
                wp_enqueue_script( 'bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array( 'jquery' ) );
            }
        }

        wp_register_style('northvantage-style', get_bloginfo('stylesheet_url'),false,null);
        wp_enqueue_style('northvantage-style');


        if(get_option('enable_responsive')!='disable') :

        wp_register_style('northvantage-responsive', get_template_directory_uri().'/stylesheets/responsive.css',false,null);
        wp_enqueue_style('northvantage-responsive');

        endif;  

        wp_enqueue_script('jquery-ui-core',false,null);
        wp_enqueue_script('jquery-ui-tabs',false,null);
        wp_enqueue_script("jquery-ui-accordion",false,null);
        wp_enqueue_script("swfobject",false,null);
        wp_deregister_script("jquery-effects-core");

        wp_deregister_script('libertas');   
        wp_register_script('libertas',get_template_directory_uri().'/js/nv-script.pack.js',false,null);
        wp_enqueue_script('libertas');  
        wp_register_script( ’streaminfo’, 'http://94.23.250.14:2199/system/streaminfo.js',false,null);
        wp_enqueue_script( ’streaminfo’ );
        wp_register_script( ’jpie’, get_template_directory_uri().'/js/jpie.js',false,null);
        wp_enqueue_script( ’jpie’ );
        wp_register_style('jpiestyle', get_template_directory_uri().'/jpie.css',false,null);
        wp_enqueue_style('jpiestyle');


        if(get_option('jwplayer_js')) { // Check jw player javascript file is present

        $NV_jwplayer_js = get_option('jwplayer_js');

        wp_deregister_script( 'jw-player' );    
        wp_register_script( 'jw-player', $NV_jwplayer_js,false,null);
        wp_enqueue_script( 'jw-player' );       
        }
    }
}    
add_action('init', 'init_dynscripts',100);


function _remove_script_version( $src ){ // remove script version
    $parts = explode( '?', $src );
    return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

看來我在streaminfo.js和我的網站之間有沖突。 元素檢驗給出:

未捕獲的TypeError:對象[對象窗口]的屬性'$'不是函數

簡而言之......我嘗試使用該文件的所有內容都錯了。

我嘗試將每個$符號更改為文件中的jQuery,它消除了沖突,但與其他文件產生沖突。

我嘗試添加

jQuery(document).ready(function($){

到文件的頭部,但它打破了CP上的其他元素。

最后,我運行了一個簡單的測試並創建了一個只包含以下代碼的網頁:

<html>
<body>
<span id="cc_strinfo_title_tranceilfm" class="cc_streaminfo"></span>
<script language="javascript" type="text/javascript" src="http://94.23.250.14:2199/system/streaminfo.js"></script>
</body>
</html>

並且頁面沒有返回任何錯誤。 (我確實包含了google jQuery文件的路徑)

Wordpress中的東西搞砸了jQuery插件? 或者我的代碼中缺少一些字符串?

www.tranceil.fm

嘗試在document.ready的頂部添加jQuery.noConflict() 這將取消綁定$變量,這應該擺脫你的沖突。

回應我們在評論中的討論,並幫助其他任何看過這個問題的人,這里有一些概述:

jQuery和jQuery.noConflicts()如何工作:

當你加載jQuery庫時,會創建一個名為jQuery的變量,它代表“jQuery”函數。 還創建了名為$ jQuery的別名。

無論出於何種原因,其他幾個javascript庫都會更改$ alias來表示自己的函數。 當發生這種情況時,你會發生沖突,因為有兩個不同的東西試圖控制$變量。 什么jQuery.noConflict()的作用是unassociates $jQuery ,允許其他任何嘗試使用$來自由地使用它。

問題是現在$並不是指jQuery ,所以在你想要訪問jQuery對象的任何地方,都需要使用jQuery而不是$

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM