javascript - Button disable after clicking issue - Stack Overflow

I have a submit button in my login page. I want to disable the submit button after clicking once.I'

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; 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 e 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="/"
    })
})
</script>
<body>
<button type="submit" id="button">Click Me!</button> 
</body>

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; 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 e 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>
Share Improve this question edited Jul 29, 2013 at 19:50 Hamed Khosravi 5457 silver badges22 bronze badges asked Jul 29, 2013 at 19:43 KousikKousik 22.5k7 gold badges38 silver badges60 bronze badges 6
  • why do you need to disable it if it goes to another page? – Sergio Commented Jul 29, 2013 at 19:45
  • @Sergio -- Probably to avoid multiple form submissions or something to that extent. – sbeliv01 Commented Jul 29, 2013 at 19:46
  • @sbeliv01, yes possible. Just curious to understand better OP's idea. – Sergio Commented Jul 29, 2013 at 19:47
  • @Sergio here my example is simple so you can feel that its not required but for form submission or ajax POST it is required otherwise it will send multiple request. – Kousik Commented Jul 29, 2013 at 19:49
  • Do you get the url from ajax call? can you not enable it on the response function of the ajax? – Sergio Commented Jul 29, 2013 at 19:51
 |  Show 1 more ment

2 Answers 2

Reset to default 2

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:

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745255940a4618956.html

相关推荐

  • javascript - Button disable after clicking issue - Stack Overflow

    I have a submit button in my login page. I want to disable the submit button after clicking once.I'

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信