如何禁用easyui中linkbutton的click事件
2个回答
展开全部
linkbutton禁用只能禁用样式,不能禁用click事件。
$('#btn').linkbutton('disable');
解决方法:
第一种方法:
juqery unbind方法
第二种方法:
判断下disable属性 $('#btn').linkbutton('disable');
$('#btn').click(function () {
if ($(this).linkbutton('options').disabled == false) {
alert('a')
}
});
第三种方法:
拓展:
function setDisabled(target, disabled) {
var state = $.data(target, "linkbutton");
if (disabled) {
state.options.disabled = true;
var href = $(target).attr("href");
if (href) {
state.href = href;
$(target).attr("href", "javascript:void(0)");
}
if (target.onclick) {
state.onclick = target.onclick;
target.onclick = null;
}
//事件处理
var events = $(target).data("events");
if(events){
var clicks = events.click;//暂时只处理click事件
state.events = state.events||[];
$.extend(state.events, clicks);
$(target).unbind("click");
}
$(target).addClass("l-btn-disabled");
} else {
state.options.disabled = false;
if (state.href) {
$(target).attr("href", state.href);
}
if (state.onclick) {
target.onclick = state.onclick;
}
if (state.events) {
for ( var i=0;i<state.events.length;i++){
$(target).bind(state.events[i].type,state.events[i].handler);
}
}
$(target).removeClass("l-btn-disabled");
}
};
$('#btn').linkbutton('disable');
解决方法:
第一种方法:
juqery unbind方法
第二种方法:
判断下disable属性 $('#btn').linkbutton('disable');
$('#btn').click(function () {
if ($(this).linkbutton('options').disabled == false) {
alert('a')
}
});
第三种方法:
拓展:
function setDisabled(target, disabled) {
var state = $.data(target, "linkbutton");
if (disabled) {
state.options.disabled = true;
var href = $(target).attr("href");
if (href) {
state.href = href;
$(target).attr("href", "javascript:void(0)");
}
if (target.onclick) {
state.onclick = target.onclick;
target.onclick = null;
}
//事件处理
var events = $(target).data("events");
if(events){
var clicks = events.click;//暂时只处理click事件
state.events = state.events||[];
$.extend(state.events, clicks);
$(target).unbind("click");
}
$(target).addClass("l-btn-disabled");
} else {
state.options.disabled = false;
if (state.href) {
$(target).attr("href", state.href);
}
if (state.onclick) {
target.onclick = state.onclick;
}
if (state.events) {
for ( var i=0;i<state.events.length;i++){
$(target).bind(state.events[i].type,state.events[i].handler);
}
}
$(target).removeClass("l-btn-disabled");
}
};
展开全部
查看linkbutton的源码,发现按钮失效时,只处理了href属性和onclick属性产生的事件。
于是重写了linkbutton的disable和enable方法,使其不触发jquery的click事件(调用了jquery底层的事件对象,1.9版)
如果linkbutton在创建时就设了disable属性,扩展无用,因为这时会调用easuyi本身的失效方法。
$.extend($.fn.linkbutton.methods, {
disable: function (jq, newposition) {
return jq.each(function () {
setDisabled(this, true);
});
},
enable: function (jq, newposition) {
return jq.each(function () {
setDisabled(this, false);
});
}
});
function setDisabled(target, disabled) {
var state = $.data(target, 'linkbutton');
var opts = state.options;
$(target).removeClass('l-btn-disabled l-btn-plain-disabled');
if (disabled) {
opts.disabled = true;
var href = $(target).attr('href');
if (href) {
state.href = href;
$(target).attr('href', 'javascript:void(0)');
}
if (target.onclick) {
state.onclick = target.onclick;
target.onclick = null;
}
if ($._data(target).events && $._data(target).events.click) {
state.jclick = $._data(target).events.click.map(function (r) {
return { namespace: r.namespace, handler: r.handler };
});
$(target).unbind('click');
}
opts.plain ? $(target).addClass('l-btn-disabled l-btn-plain-disabled') : $(target).addClass('l-btn-disabled');
} else {
opts.disabled = false;
if (state.href) {
$(target).attr('href', state.href);
}
if (state.onclick) {
target.onclick = state.onclick;
}
if (state.jclick)
for (var i = 0; i < state.jclick.length; i++) {
var click = state.jclick[i];
$(target).bind('click' + (click.namespace ? '.' + click.namespace : ''), click.handler);
}
}
}
转 http://blog.csdn.net/rainxie_/article/details/52766813
于是重写了linkbutton的disable和enable方法,使其不触发jquery的click事件(调用了jquery底层的事件对象,1.9版)
如果linkbutton在创建时就设了disable属性,扩展无用,因为这时会调用easuyi本身的失效方法。
$.extend($.fn.linkbutton.methods, {
disable: function (jq, newposition) {
return jq.each(function () {
setDisabled(this, true);
});
},
enable: function (jq, newposition) {
return jq.each(function () {
setDisabled(this, false);
});
}
});
function setDisabled(target, disabled) {
var state = $.data(target, 'linkbutton');
var opts = state.options;
$(target).removeClass('l-btn-disabled l-btn-plain-disabled');
if (disabled) {
opts.disabled = true;
var href = $(target).attr('href');
if (href) {
state.href = href;
$(target).attr('href', 'javascript:void(0)');
}
if (target.onclick) {
state.onclick = target.onclick;
target.onclick = null;
}
if ($._data(target).events && $._data(target).events.click) {
state.jclick = $._data(target).events.click.map(function (r) {
return { namespace: r.namespace, handler: r.handler };
});
$(target).unbind('click');
}
opts.plain ? $(target).addClass('l-btn-disabled l-btn-plain-disabled') : $(target).addClass('l-btn-disabled');
} else {
opts.disabled = false;
if (state.href) {
$(target).attr('href', state.href);
}
if (state.onclick) {
target.onclick = state.onclick;
}
if (state.jclick)
for (var i = 0; i < state.jclick.length; i++) {
var click = state.jclick[i];
$(target).bind('click' + (click.namespace ? '.' + click.namespace : ''), click.handler);
}
}
}
转 http://blog.csdn.net/rainxie_/article/details/52766813
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询