繁体   English   中英

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

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

单击按钮后,我有一个禁用的按钮,在页面加载时,我获取按钮的状态,然后根据要求启用和禁用该按钮。它工作正常,但我为按钮提供了一个点击事件。 当按钮被禁用时,当我点击按钮时,javascript 也会调用一个方法。

我有标签作为按钮。 当按钮被禁用时我如何处理引发事件停止。

先感谢您。

<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" );
    }
    
})

尝试这个:

 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>

尝试这个:

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

或者您可以尝试在单击时添加一个禁用按钮的 css 类:

.disabled {
    pointer-events: none;
}

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

暂无
暂无

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

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