1
我有以下的代碼片斷..jQuery代碼錯誤在IE瀏覽器,但沒有其他的瀏覽器
我得到的錯誤
預期標識符,字符串或數字
上線...
options.reference = '.' + $(this).attr('class');
然後在插件...
對象不支持此屬性或方法
就行了...
if ($target.is(options.reference) || $target.closest(options.reference).length)
return false;
這些造成任何瀏覽器,但IE瀏覽器沒有問題。它也是IE8,而不是6. 以下是ENTIRE插件,供參考。
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');
}
});
};
這並不能真正回答任何問題。即使我用硬編碼的類名替換它,也會出現相同的錯誤。 – Ciel 2010-09-29 04:42:59
發佈你正在使用的HTML,不能幫你瞎子。 – xmarcos 2010-09-29 23:24:29