2015-04-03 122 views
0

編輯:

Here is the full HTML這是太長,我可以直接粘貼在這裏。我沒有創建這個頁面,我只是要清理它的問題。


我試圖從運行裏面的$(document)。就緒的功能,因爲我需要用DOM在我的函數運行之前完成加載,因爲我是綁定按鈕。這就是我的腳本中的內容:

jQuery(function($) { 
    alert('foo'); 
    SI.regionSelector.init(); 
}); 

我也試過:

$(document).ready(function(){ 
    alert('foo'); 
    SI.regionSelecter.init(); 
}); 

但警報從未發生過。我已經在Chrome中使用調試器。我打jQuery(函數($),我沒有得到任何錯誤(事實上控制檯顯示什麼jQuery被定義爲,所以我知道我的頁面上有jQuery),然後調試器跳轉到jQuery函數的結尾,但它根本不會去報警

以下是完整的腳本:

var SI = SI || {}; 

SI.regionSelector = { 
    settings: {}, 
    regions: [], 
    init: function() { 
    jQuery('a').click(function(e){ e.preventDefault(); }); 
    // Start the DOMSelection tool when a region is clicked 
    jQuery('#region-selector .region').click(function(){ 
     targetRegion = jQuery(this); 
     SetupDOMSelection(); 
    }); 

    // When saving, pull the values stored by the DOMSelection tool 
    // and stuff them into hidden fields so they can be picked up on 
    // the back end. 
    jQuery('#region-selector .save').click(function(){ 
     jQuery('#site_ingestor_region_selector .btn.region').each(function(){ 
     var values = {}; 
     values.innerHTML = jQuery(this).data('innerHTML'); 
     values.xpath = jQuery(this).data('xpath'); 
     var id = jQuery(this).attr('id'); 
     var $hiddenInput = jQuery('input[name="'+id.replace('btn', 'form-region')+'"]'); 
     $hiddenInput.val(JSON.stringify(values)); 
     }); 
    }); 

    jQuery('.btn.edit').click(function() { 
     jQuery('#site_ingestor_html_editor').css('display', 'block'); 
     jQuery('body').css('overflow', 'hidden'); 
     window.scrollTo(0, 0); 
    }); 
    jQuery('.btn.cancel').click(function() { 
     jQuery('#site_ingestor_html_editor').css('display', 'none'); 
     jQuery('body').css('overflow', 'scroll'); 
     }); 
     } 
}; 

jQuery(function($) { 
    alert('foo'); 
    SI.regionSelector.init(); 
}); 
+0

在您的網頁上,此代碼是在哪? – theonlygusti 2015-04-03 14:26:13

+0

請添加周圍的html區域...也許你的腳本沒有正確定義 – 2015-04-03 14:26:23

+4

你能添加完整的代碼來重現問題嗎? – activatedgeek 2015-04-03 14:26:54

回答

1

有些事情我會檢查:

  • 確保jQuery的.js文件庫腳本之前引用
  • 確保您的$(或jQuery,這取決於你使用的是什麼)不與瀏覽器的JS控制檯任何其他庫
  • 檢查其他JS錯誤(或其他信息)發生衝突

我也跑完整的Markup page validation(也許修剪一些標記,以減少複雜性),看看是否有一些明顯的HTML錯誤,如缺少關閉身體標記或類似的東西。

+1

「確保你的$不與任何其他庫衝突」?爲什麼?它在0個地方使用。 – theonlygusti 2015-04-03 14:36:52

+0

那麼他開始與「我試圖從$(文檔).ready內運行一個函數」......無論如何,得到你的觀點:編輯:) – Darkseal 2015-04-03 14:42:04