我(试图)从CDN加载jQuery 1.9.1:“Uncaught TypeError:无法调用未定义的jquery-1.9.1.js:648的方法'调用'”。所以我更新了参考文献,显然得到了一个等效的错误,现在用于缩小:
Uncaught TypeError: Cannot call method 'call' of undefined jquery-1.11.0.min.js:2
n.extend.each jquery-1.11.0.min.js:2
(anonymous function) site.js:26
j jquery-1.11.0.min.js:2
k.fireWith jquery-1.11.0.min.js:2
n.extend.ready jquery-1.11.0.min.js:2
K jquery-1.11.0.min.js:2
页面位于http://ccachicago.pragmatometer.com;第一个SCRIPT标签是:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
(页面是POSH加上CSS样式和轻松的JavaScript尘埃;现代webapp标准很简单......)
- 编辑 -
关于我的代码,该页面只有脚本内容:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="/media/js/site.js"></script>
<script>
function slideshow()
{
var width = (jQuery(window).width() - 70) * .8;
var factor = width / 1024;
var height = 420 * factor;
jQuery('#slideshow').attr('height', height + 'px');
jQuery('#slideshow').attr('width', width + 'px');
};
slideshow();
jQuery(window).resize(slideshow);
</script>
site.js文件包含:
/** * Override jQuery.fn.init to guard against XSS attacks. * * See http://bugs.jquery.com/ticket/9521 */ (function () { var jquery_init = jQuery.fn.init; jQuery.fn.init = function (selector, context, rootjQuery) { // If the string contains a "#" before a "= 0) { var bracket_position = selector.indexOf(' hash_position) { throw 'Syntax error, unrecognized expression: ' + selector; } } } return jquery_init.call(this, selector, context, rootjQuery); }; jQuery.fn.init.prototype = jquery_init.prototype; })(); jQuery(function() { jQuery.each(jQuery('h1').add('h2').add('h3').add('h4').add('h5').add('h6').add('ul#navigation')).function(index, element) { var bounds = jQuery(element).offset(); var image_left = bounds.left; var image_top = bounds.top + bounds.height; var image = jQuery(''); image.style.position = 'absolute'; image.style.top = image_top + 'px'; image.style.left = image_left + 'px'; } function set_search_width() { var offset = 950; var width = jQuery(window).width() - offset; jQuery('#menu-search').css('max-width', width + 'px'); jQuery('#menu-search').css('width', width + 'px'); jQuery('#query').width(width - 80); } jQuery(window).resize(set_search_width); set_search_width(); }); sfHover = function() { var sfEls = document.getElementById('nav').getElementsByTagName('li'); for(var index = 0; index/** * Override jQuery.fn.init to guard against XSS attacks. * * See http://bugs.jquery.com/ticket/9521 */ (function () { var jquery_init = jQuery.fn.init; jQuery.fn.init = function (selector, context, rootjQuery) { // If the string contains a "#" before a "<", treat it as invalid HTML. if (selector && typeof selector === 'string') { var hash_position = selector.indexOf('#'); if (hash_position >= 0) { var bracket_position = selector.indexOf('<'); if (bracket_position > hash_position) { throw 'Syntax error, unrecognized expression: ' + selector; } } } return jquery_init.call(this, selector, context, rootjQuery); }; jQuery.fn.init.prototype = jquery_init.prototype; })(); jQuery(function() { jQuery.each(jQuery('h1').add('h2').add('h3').add('h4').add('h5').add('h6').add('ul#navigation')).function(index, element) { var bounds = jQuery(element).offset(); var image_left = bounds.left; var image_top = bounds.top + bounds.height; var image = jQuery('<img src="/media/images/foldback.png">'); image.style.position = 'absolute'; image.style.top = image_top + 'px'; image.style.left = image_left + 'px'; } function set_search_width() { var offset = 950; var width = jQuery(window).width() - offset; jQuery('#menu-search').css('max-width', width + 'px'); jQuery('#menu-search').css('width', width + 'px'); jQuery('#query').width(width - 80); } jQuery(window).resize(set_search_width); set_search_width(); }); sfHover = function() { var sfEls = document.getElementById('nav').getElementsByTagName('li'); for(var index = 0; index < sfEls.length; index++) { sfEls[i].onmouseover = function() { this.className += " sfhover"; } sfEls[i].onmouseout = function() { this.className = this.className.replace(new RegExp( " sfhover\\b"), ""); } } } if (window.attachEvent) { window.attachEvent("onload", sfHover); }
答案 0 :(得分:3)
你的SYNxis不正确
你想做什么?
jQuery(function()
{
jQuery.each(jQuery('h1').add('h2').add('h3').add('h4').add('h5').add('h6').add('ul#navigation')).function(index, element)
{
var bounds = jQuery(element).offset();
var image_left = bounds.left;
var image_top = bounds.top + bounds.height;
var image = jQuery('<img src="/media/images/foldback.png">');
image.style.position = 'absolute';
image.style.top = image_top + 'px';
image.style.left = image_left + 'px';
}
function set_search_width()
{
var offset = 950;
var width = jQuery(window).width() - offset;
jQuery('#menu-search').css('max-width', width + 'px');
jQuery('#menu-search').css('width', width + 'px');
jQuery('#query').width(width - 80);
}
jQuery(window).resize(set_search_width);
set_search_width();
});
下面的代码可能是你想要的? (找到元素,我认为最好使用复杂的选择器,并将函数应用于每个元素)
jQuery('h1').add('h2').add('h3').add('h4').add('h5').add('h6').add('ul#navigation').each(function(index, element)
{
var bounds = jQuery(element).offset();
var image_left = bounds.left;
var image_top = bounds.top + bounds.height;
var image = jQuery('<img src="/media/images/foldback.png">');
image.style.position = 'absolute';
image.style.top = image_top + 'px';
image.style.left = image_left + 'px';
});
答案 1 :(得分:1)
违规行是:site.js line 26
如果应该像
那样jQuery.each(jQuery('h1').add('h2'), function(index, element) { ... })
不
jQuery.each(jQuery('h1').add('h2')).function(index, element) { ... }