BootStrap中按鈕點擊后被禁用按鈕的最佳實現方法


//禁用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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM