jQuery preventDefault + trigger 结合使用注意事项

最近写一个类似outlookbar的界面的JQuery插件发现。如下问题代码如下:

var settings = {
openTag: "a:first", //默认第一个标签的查询条件
attrName: "_for", //a 目的地址
selStyleCss: "thisclass", //选中样式的css
eventName: "click", //事件名称
modifyStyleCss: "background-position", //css样式,通过此样式实现上下箭头的变换
downStyle: "left bottom", //下箭头
upStyle: "left top", //上箭头
navWorkspace: "#workspace", //工作空间导航id
workspace: "#mainContent", //工作空间ID
duration: "fast"
}, navsel;
function isVisible(elem) {
return elem.is(":visible");
}
function ChangeNav(cur) {
SetNavUnSelected(navsel);
SetNavSelected(cur);
navsel = cur;
}
function SetNavSelected(nav) {
var url;
url = nav.attr(settings.attrName);
nav.addClass(settings.selStyleCss);
$(url).show();
}
function SetNavUnSelected(nav) {
var url;
url = nav.attr(settings.attrName);
nav.removeClass(settings.selStyleCss);
$(url).hide();
}
jQuery.fn.outlookbar = function () {
var beforeA;
$(document).ajaxStart(function () {
$.blockUI({
message: '<img src="../Content/images/busy.gif" alt="请等待..."/>',
css: {
backgroundColor: "#666666",
opacity:0.5,
top: ($(window).height() - 32) / 2 + "px",
left: ($(window).width() - 32) / 2 + "px",
width: "32px",
border: "none"
}
});
});
$(document).ajaxStop(function () {
$.unblockUI();
});
this.delegate("dt", settings.eventName, function () {
var $dt, $dd;
$dt = $(this);
$dd = $dt.siblings("dd");
if (!isVisible($dd)) {
$dt.css(settings.modifyStyleCss, settings.downStyle);
}
else {
$dt.css(settings.modifyStyleCss, settings.upStyle);
}
$dd.slideToggle(settings.duration);
});
this.delegate("a", settings.eventName, function () {
var $workspace, $self, urlAjax;
$workspace = $(settings.workspace);
$self = $(this);
urlAjax = $self.attr("_for");
if (!isVisible($workspace)) {

//出问题的代码

$(settings.navWorkspace).trigger("click");  //问题:执行这句代码以后不继续执行后面的函数了。后来发现$(settings.navWorkspace).click事件包含preventDefault。此处直接返回了不知道为啥?是Bug还是?请各位大侠指导!!!


  // 解决问题的新代码 ChangeNav($(settings.navWorkspace)); 
}
$self.addClass(settings.selStyleCss);
if (beforeA) {
beforeA.removeClass(settings.selStyleCss);
}
beforeA = $self;
$.ajax({
type: "GET",

url: urlAjax,
cache: false,
success: function (data) {
$(settings.workspace).html(data);
},
error: function (data, status, set) {
$(settings.workspace).html(data);
}
});
event.preventDefault();
});
};
jQuery.fn.navmenu = function () {
navsel = this.find(settings.openTag);
this.delegate("a", settings.eventName, function () {
var $self;
$self = $(this);
if (!$self.hasClass(settings.selStyleCss)) {
ChangeNav($self);
}
event.preventDefault();
});
};

你可能感兴趣的:(jquery,工作,function,url,jquery插件,border)