IE中的jQuery代码错误,但没有其他浏览器
我有以下代码片段 我得到了错误 应为标识符、字符串或数字 在线上IE中的jQuery代码错误,但没有其他浏览器,jquery,internet-explorer-8,Jquery,Internet Explorer 8,我有以下代码片段 我得到了错误 应为标识符、字符串或数字 在线上 options.reference = '.' + $(this).attr('class'); if ($target.is(options.reference) || $target.closest(options.reference).length) return false; 之后在插件中 对象不支持此属性或方法 在线上 options.reference = '
options.reference = '.' + $(this).attr('class');
if ($target.is(options.reference) || $target.closest(options.reference).length)
return false;
之后在插件中
对象不支持此属性或方法
在线上
options.reference = '.' + $(this).attr('class');
if ($target.is(options.reference) || $target.closest(options.reference).length)
return false;
除了IE之外,这些都不会在任何浏览器中引起问题。它也是IE8,而不是6。
下面是整个插件,供参考
jQuery.fn.dropdown = function () {
var defaults = {
reference: null,
button: null,
menu: null
};
return this.each(function () {
// initialize options for each dropdown list, since there
// very well may be more than just one.
var options = $.extend(defaults, options);
// specifically assign the option components.
options.reference = '.' + $(this).attr('class');
options.list = $(this);
options.button = $(this).find('> a');
options.menu = $(this).find('> div');
// bind the lift event to the document click.
// This will allow the menu to collapse if the user
// clicks outside of it; but we will stop event bubbling to
// keep it from being affected by the internal document links.
$(document).click(function (e) {
var $target = $(e.target);
// check to see if we have clicked on one of the dropdowns, and if so, dismiss
// the execution. We only want to lift one if we're not trying to interact with
// one.
if ($target.is(options.reference) || $target.closest(options.reference).length)
return false;
lift(e);
});
// when the button is clicked, determine the state of the
// dropdown, and decide whether or not it needs to be lifted
// or lowered.
options.button.click(function (e) {
options.menu.is(':visible') ? lift() : drop();
e.stopPropogation(); // prevent event bubbling
});
// drop the menu down so that it can be seen.
function drop(e) {
// show the menu section.
options.menu.show();
// style the button that drops the menu, just for aesthetic purposes.
options.list.addClass("open");
}
// lift the menu up, hiding it from view.
function lift(e) {
if (!options.menu.is(':visible'))
return;
options.menu.hide();
// style the button that drops the menu, just for aesthetic purposes.
options.list.removeClass('open');
}
});
};
插件设计很差,如果元素有多个类,
$(this).attr('class')
将返回一个字符串,如.class1 class2 classN
,这会破坏插件
这不是IE的问题,而是糟糕的代码。这并不能真正回答任何问题。即使我用一个硬编码的类名替换它,它也会给出同样的错误。发布你正在使用的HTML,不能帮助你解决这个问题。