2013-06-26 82 views
6

我想創建使用JavaScript和jQuery在Salesforce控件方法「noConflict」,我被套牢了錯誤:遺漏的類型錯誤:無法調用未定義遺漏的類型錯誤:無法調用未定義

法「noConflict」

下面是我的代碼,我使用

(function() { 

// Localize jQuery variable 
var $j; 

/******** Load jQuery if not present *********/ 
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') { 
    var script_tag = document.createElement('script'); 
    script_tag.setAttribute("type","text/javascript"); 
    script_tag.setAttribute("src", 
     "https://ap1.salesforce.com/resource/go/jquery.min.js"); 
    if (script_tag.readyState) { 
     script_tag.onreadystatechange = function() { // For old versions of IE 
      if (this.readyState == 'complete' || this.readyState == 'loaded') { 
       scriptLoadHandler(); 
      } 
     }; 
    } else { 
     script_tag.onload = scriptLoadHandler; 
    } 
    // Try to find the head, otherwise default to the documentElement 
    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); 
} else { 
    // The jQuery version on the window is the one we want to use 
    $j = window.jQuery; 
    main(); 
} 

/******** Called once jQuery has loaded ******/ 
function scriptLoadHandler() { 
    // Restore $ and window.jQuery to their previous values and store the 
    // new jQuery in our local jQuery variable 
    $j = window.jQuery.noConflict(true); 
    // Call our main function 
    main(); 
} 

/******** Our main function ********/ 
function main() { 
    $j(document).ready(function($) { 
     /******* Load CSS *******/ 
     var css_link = $("<link>", { 
      rel: "stylesheet", 
      type: "text/css", 
      href: "style.css" 
     }); 
     css_link.appendTo('head');   

     /******* Load HTML *******/ 
     var jsonp_url = "http://al.smeuh.org/cgi-bin/webwidget_tutorial.py?callback=?"; 
     $.getJSON(jsonp_url, function(data) { 
      $('#example-widget-container').html("This data comes from another server: " + data.html); 
     }); 

    }); 
} 

})(); // We call our anonymous function immediately 

在瀏覽器控制檯錯誤指向到scriptLoadHandler功能的第一道防線。

+0

你有沒有在你的 –

+0

頁面包括jQuery的是我做的,我動態,包括它通過檢查與如果現有的或沒有,你可以看到它在上述代碼的第三行。 –

+0

當我打開https://ap1.salesforce.com/resource/go/jquery.min.js它似乎不包含jQuery代碼。你有沒有嘗試從其他地方包括jquery? – Reason

回答

2

聲明如下本地jQuery的變量:

//Localize jQuery variable 
var $j = jQuery.noConflict(); 
相關問題