如果(确认)条件,如果从javascript确认,我怎么能防止点击按钮多次点击

时间:2021-07-28 10:38:50
<input type="button" onclick="return saveValues();" value="<?php echo "values" ?>" class="silver_button_big">

On the above to stop the multiclick i have tried something like this.

在上面停止多点击我尝试过这样的事情。

my_toggle_var = 0; // your global variable which u can use to play 
function saveValues() {

if (my_toggle_var  == 0)
{
    ic.do.something();
    my_toggle_var  = 1; // You can move it up down based on your need....
}
},

 something : function(){
  //some code
  //these code lead to run some jar file
  // data insertion into DB(using mysql)

}

But this is unable to solve my problem in above case, i can say there may be some sort of browser cache problem. Can somebody help me out.

但是在上面的情况下这无法解决我的问题,我可以说可能存在某种浏览器缓存问题。有人可以帮助我吗?

1 个解决方案

#1


4  

Just set disabled="disabled" and readonly="readonly" attributes:

只需设置disabled =“disabled”和readonly =“readonly”属性:

// Attach the click handler
$(".silver_button_big").on("click", function() {

  var $this = $(this);

  // Disable button
  $this.attr({"disabled": "disabled", "readonly": "readonly"});

  // Do something async
  setTimeout(function() {
    
    // Enable the button back
    $this.removeAttr("disabled readonly");
  }, 1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Click me" class="silver_button_big">

Note that it's recommended not to use empty attribute values.

请注意,建议不要使用空属性值。

#1


4  

Just set disabled="disabled" and readonly="readonly" attributes:

只需设置disabled =“disabled”和readonly =“readonly”属性:

// Attach the click handler
$(".silver_button_big").on("click", function() {

  var $this = $(this);

  // Disable button
  $this.attr({"disabled": "disabled", "readonly": "readonly"});

  // Do something async
  setTimeout(function() {
    
    // Enable the button back
    $this.removeAttr("disabled readonly");
  }, 1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Click me" class="silver_button_big">

Note that it's recommended not to use empty attribute values.

请注意,建议不要使用空属性值。