/** * 按钮禁用10秒 * @param submitButtonName 按钮ID名 */ function disabledSubmitButton(submitButtonName) { $("#" + submitButtonName).attr({ "disabled": "disabled" }); //控制按钮为禁用 var timeoutObj = setTimeout(function () { $("#" + submitButtonName).removeAttr("disabled");//将按钮可用 /* 清除已设置的setTimeout对象 */ clearTimeout(timeoutObj) }, 1000); }
方式二:禁用10秒,10秒钟后可用,且有倒计时提示
/** * 按钮禁用10秒,并显示倒计时 * @param submitButtonName 按钮ID名 * @param submitButtonText 按钮显示文本 */ function disabledSubmitButton02(submitButtonName, submitButtonText) { $("#" + submitButtonName).attr({ "disabled": "disabled" }); //控制按钮为禁用 var second = 10; var intervalObj = setInterval(function () { $("#" + submitButtonName).text(submitButtonText + "(" + second + ")"); if (second == 0) { $("#" + submitButtonName).text(submitButtonText); $("#" + submitButtonName).removeAttr("disabled");//将按钮可用 /* 清除已设置的setInterval对象 */ clearInterval(intervalObj); } second--; }, 1000); }