需求:点击一个a标签/按钮需要禁用几秒(最好改变相应文字颜色),计时结束后恢复其相应功能
a标签:
核心代码
禁用:
$(’#elementName’).removeAttr(‘href’);/去掉a标签中的href属性
$(’#elementName’).removeAttr(‘onclick’);//去掉a标签中的onclick事件
恢复:
$(’#elementName’).attr(‘href’,‘url’);
$(’#elementName’).attr(‘onclick’);
//重置密码
function resetPwd(aid) {
$.post('../admin.action?op=reSetPwd', {
aid : aid
}, function(data) {
if (data > 0) {
alert('密码重置成功!重置按钮将锁定5秒钟!');
var aTag = $('#reSetAdminPwd');
aTag.css('color', '#787890');//a标签设为灰色
aTag.removeAttr('href');
aTag.removeAttr('onclick');
//按钮禁用10秒的函数
var timeOutObj = setTimeout(function() {
aTag.css('color', '#0000F1');//a标签设为蓝色
aTag.attr('href','javascript:resetPwd('+aid+')');
aTag.attr('onclick');
// 清除已设置的setTimeout对象
clearTimeout(timeOutObj);
}, 5000);
} else {
alert('密码重置失败!噗嗤.jpg!');
}
}, 'json');
}
});
按钮:
禁用:
$(’#button’).attr(‘disabled’,“true”);//添加disabled属性
$(’#button’).removeAttr(“disabled”);// 移除disabled属性