$(文件)。就绪和jQuery(函数($)不工作; jQuery的定义,但剧本没有进入。就绪功能

问题描述:

编辑:

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

有些事情我会检查:

  • 确保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