简体   繁体   English

当按钮被禁用时,点击事件调用

[英]when button is disable then also on click event call

once the button clicked I have a disabled button and on page load, I get the status of the button and then enable and disable the button according to requirement.it's work properly but I give an on-click event to the button.单击按钮后,我有一个禁用的按钮,在页面加载时,我获取按钮的状态,然后根据要求启用和禁用该按钮。它工作正常,但我为按钮提供了一个点击事件。 when the button is disabled then also when I click the button javascript call a method.当按钮被禁用时,当我点击按钮时,javascript 也会调用一个方法。

i have tag as a button.我有标签作为按钮。 how I can handle when button is disabled raise event stop.当按钮被禁用时我如何处理引发事件停止。

thank you in advance.先感谢您。

<a id="check_status_api" class="btn btn-info btn-sm" href="javascript:void(0)">run_batch</a>

$("#check_status_api").click(function(e){
  console.log('my ajax call code ')
})

$(document).ready(function(){
  //on page load get status of my batch if it's running then button disable property add 
    if ('runnig' == 'runnig'){
      $("#check_status_api").attr( "disabled", "disabled" );
    }
    
})

Try this:尝试这个:

 const myBtn = $('#check_status_api') myBtn.click(function(e){ if (!myBtn.is('[disabled=disabled]')) { console.log('my ajax call code ') } }) $(document).ready(function(){ //on page load get status of my batch if it's running then button disable property add if ('runnig' == 'runnig'){ myBtn.attr( "disabled", "disabled" ); } })
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <a id="check_status_api" class="btn btn-info btn-sm" href="javascript:void(0)">run_batch</a>

try this:尝试这个:

$("btn btn-info btn-sm").prop('disabled', true);

or you can try adding a css class on click that disables the button:或者您可以尝试在单击时添加一个禁用按钮的 css 类:

.disabled {
    pointer-events: none;
}

or document.getElementById("check_status_api").disabled = true;document.getElementById("check_status_api").disabled = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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