jQuery禁用a标签和禁用按钮click点击的方法

禁用a标签方法一

1
2
3
4
5
6
7
8
9
10
11
12
$(document).ready(function () {
$("a").each(function () {
var textValue = $(this).html();
if (textValue == "XX概况" || textValue == "服务导航") {
$(this).css("cursor", "default");
$(this).attr('href', '#'); //修改<a>的 href属性值为 # 这样状态栏不会显示链接地址
$(this).click(function (event) {
event.preventDefault(); // 如果<a>定义了 target="_blank“ 需要这句来阻止打开新页面
});
}
});
});

禁用a标签方法二

1
2
3
4
$('a.tooltip').live('click', function(event) {
alert("抱歉,已停用!");
event.preventDefault();
});

禁用a标签方法三

1
2
3
4
$(function(){
$('.disableCss').removeAttr('href');//去掉a标签中的href属性
$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件
});

控制按钮的禁用与启用
$('#button').attr('disabled',"true");添加disabled属性
$('#button').removeAttr("disabled"); 移除disabled属性
注意:.attr('disabled',"true");<a>链接无效。

另外可参考文章:JS绑定事件和移除事件的处理方法