简体   繁体   English

点击问题后按钮禁用

[英]Button disable after clicking issue

I have a submit button in my login page. 我的登录页面中有一个提交按钮。 I want to disable the submit button after clicking once.I'ts working fine with this.disabled = true; 我想在点击一次后禁用提交按钮。我的工作正常与this.disabled = true; query and after disable the button it's going to the next page. 查询并禁用按钮后,它将转到下一页。 The problem is that when I press back button it's still is disable because the page is not reloaded from server,It's loading from the local cache. 问题是,当我按下后退按钮时,它仍然是禁用的,因为页面没有从服务器重新加载,它是从本地缓存加载的。 I want to enable the button every time when I come back to the login page. 我想每次回到登录页面时都启用该按钮。 I can clear the cache but there is some problem like if it will load from the server and project will be slow. 我可以清除缓存,但有一些问题,如果它将从服务器加载,项目将是缓慢的。 What will be the best way to do this? 最好的方法是什么?

<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>

You need another event that ensures the button is enabled on page load. 您需要另一个事件来确保在页面加载时启用该按钮。 Kind of like: 有一些像:

<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>

I didn't try running this so I'm not sure if the syntax is 100% but it should give you the right idea. 我没有尝试运行这个,所以我不确定语法是100%,但它应该给你正确的想法。

I set the buttons initial disabled attribute to disabled in the body html to prove that the code does enable it again (so you can remove that in the body) I hope this helps: 我在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM