(function($){
function setDisabled(target, disabled){
var state = $.data(target, 'e7button');
state.options = state.options || {};
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;
}
$(target).css({'opacity':'0.5','cursor':'default'});
} else {
state.options.disabled = false;
if (state.href) {
$(target).attr('href', state.href);
}
if (state.onclick) {
target.onclick = state.onclick;
}
$(target).css({'opacity':'1','cursor':'pointer'});
}
$.data(target, 'e7button',state);
}
$.fn.e7button = function(options){
if (typeof options == 'string'){
return $.fn.e7button.methods[options](this);
}
};
$.fn.e7button.methods = {
enable: function(jq){
return jq.each(function(){
setDisabled(this, false);
});
},
disable: function(jq){
return jq.each(function(){
setDisabled(this, true);
});
}
};
})(jQuery);
js 自定义控件 启用禁用按钮状态
最新推荐文章于 2024-06-20 10:18:03 发布