How to prevent a button from being clicked several times in a short time

Source: Internet
Author: User
Tags setinterval

  A button can be clicked more than once in a short period of time, it is possible to be malicious users click, there is a good way to stop, I hope to help you.

If a button can be clicked more than once in a short period of time, it may be malicious clicks of the user, in order to prevent this situation, you can set a certain time to click only once, other times prohibit the click button.     Code as follows:  <html xmlns= "http://www.w3.org/1999/xhtml" >  <head runat= "Server" >  <title>js timed Event </title>  <script src= "js/jquery-1.9.1.js" type= "Text/javascript" ></script >  </head>  <body>  <form id= "Form1" runat= "Server" >  <div>  < Input type= "button" value= "click Me" id= "btn" onclick= "Show ()"/>  </div>  <script type= "text/ JavaScript "> /*  timeid=window.settimeout (" Method () ", 1000); Window.cleartimeout (Timeid), timed execution   Timeid=window.setinterval ("Method ()", 1000); Window.clearinterval (Timeid); loop execution   */    var nn = 30;  var tipid;  function Show () {  Tipid = Window.setinterval ("Start ()", 1000); Call Start () method every 1 seconds  }    function start () {  if (nn > 0) {  var vv = "Click me (" + NN + ")";  $ ("#btn"). attr ("Disabled", "disablEd "); Make the button cannot be clicked   $ ("#btn"). attr ("value", VV); Change the text on the button   nn--; } else {  nn = 30;  $ ("#btn"). Removeattr ("Disabled");//enable button to be clicked   $ ("#btn"). attr ("value", "Point Me Down"); Change the text on the button   Window.clearinterval (tipid); Purge Cycle events  } }  </script>  </form>  </body>  </html>   
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.