[英]Button disable after clicking issue
我的登錄頁面中有一個提交按鈕。 我想在點擊一次后禁用提交按鈕。我的工作正常與this.disabled = true;
查詢並禁用按鈕后,它將轉到下一頁。 問題是,當我按下后退按鈕時,它仍然是禁用的,因為頁面沒有從服務器重新加載,它是從本地緩存加載的。 我想每次回到登錄頁面時都啟用該按鈕。 我可以清除緩存,但有一些問題,如果它將從服務器加載,項目將是緩慢的。 最好的方法是什么?
<script>
$(document).ready(function(){
$(document).on('click','button',function(){
this.disabled = true
window.location="https://www.google.co.in/"
})
})
</script>
<body>
<button type="submit" id="button">Click Me!</button>
</body>
您需要另一個事件來確保在頁面加載時啟用該按鈕。 有一些像:
<script>
$(document).ready(function(){
$("#button").disabled = false;
$(document).on('click','button',function(){
this.disabled = true
window.location="https://www.google.co.in/"
})
})
</script>
<body>
<button type="submit" id="button">Click Me!</button>
</body>
我沒有嘗試運行這個,所以我不確定語法是100%,但它應該給你正確的想法。
我在body html中將按鈕初始禁用屬性設置為禁用,以證明代碼再次啟用它(所以你可以刪除它在體內)我希望這有助於:
<script>
$(document).ready(function () {
$("#button").removeAttr('disabled');
$("#button").click(function(){
$(this).attr('disabled','disabled');
window.location="https://www.google.co.in/"
});
});
</script>
<body>
<button type="submit" id="button" disabled="disabled">Click Me!</button>
</body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.