//禁用button
$(
'button'
).addClass(
'disabled'
);
// Disables visually
$(
'button'
).prop(
'disabled'
,
true
);
// Disables visually + functionally
//禁用類型為button的input按鈕
$(
'input[type=button]'
).addClass(
'disabled'
);
// Disables visually
$(
'input[type=button]'
).prop(
'disabled'
,
true
);
// Disables visually + functionally
//禁用超鏈接
$(
'a'
).addClass(
'disabled'
);
// Disables visually
$(
'a'
).prop(
'disabled'
,
true
);
// Does nothing
$(
'a'
).attr(
'disabled'
,
'disabled'
);
// Disables visually
將上面方法寫入點擊事件中即可,如:
$(
".btn-check"
).click(
function
() {
$(
'button'
).addClass(
'disabled'
);
// Disables visually
$(
'button'
).prop(
'disabled'
,
true
);
// Disables visually + functionally
});
js按鈕點擊后幾秒內不可用:
function
timer(time) {
var
btn = $(
"#sendButton"
);
btn.attr(
"disabled"
,
true
);
//按鈕禁止點擊
btn.val(time <= 0 ?
"發送動態密碼"
: (
""
+ (time) +
"秒后可發送"
));
var
hander = setInterval(
function
() {
if
(time <= 0) {
clearInterval(hander);
//清除倒計時
btn.val(
"發送動態密碼"
);
btn.attr(
"disabled"
,
false
);
return
false
;
}
else
{
btn.val(
""
+ (time--) +
"秒后可發送"
);
}
}, 1000);
}
//調用方法
timer(30);