繁体   English   中英

成功的Ajax请求后,如何禁用onclick事件?

[英]How can i disable onclick event after successful ajax request?

我想在成功的Ajax请求后禁用onclick事件

<div class="report_button" id="report_button" title="Reportthis" style="width:65px;height:15px;" onclick="reported_text(user_id,lead_id);">Report</div>

这是我的div,我想在单击后禁用div

function reported_text(user_id,lead_id){
    new Ajax.Request("/agent/report/lead-refund",
    {
        method:"POST",
        parameters:"user_id=" + user_id + "&lead_id=" + lead_id ,
        onSuccess: function(transport){
            alert("Thank you for Response");
            jQuery('#report_button').attr("disabled", "disabled");
        },
        onFailure: function(transport){

            $('tag_error_status').innerHTML = '';
            alert("Unsuccessful request processing. This will be rectified soon.");
        }
    });
}

有没有办法做到这一点。 并且此div用于许多用户,我必须以某种方式使用它,以便仅对特定用户禁用。

 new Ajax.Request("/agent/report/lead-refund",
    {
        method:"POST",
        parameters:"user_id=" + user_id + "&lead_id=" + lead_id ,
        onSuccess: function(transport){
            alert("Thank you for Response");
            jQuery('#report_button').hide();
        },
        onFailure: function(transport){

            $('tag_error_status').innerHTML = '';
            alert("Unsuccessful request processing. This will be rectified soon.");
        }
    });

您可以使用hide函数来这样做...,也可以使用$("#report_button").attr("onclick","")

根据您添加监听器的方式,尝试适合的监听器:如果使用$(document).on则使用:

$(document).off("click", "#report_button");

如果您使用$(“#report_button”)。on,则使用:

$("#report_button").off

或仅使用:

$("#report_button").click(function(){ return false; });

您可以像这样禁用点击:

document.getElementById("report_button").onmousedown = new function ("return false");

这是我找到此代码链接的地方

暂无
暂无

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

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