Javascript Jquery click函数不应再次调用

Javascript Jquery click函数不应再次调用,javascript,jquery,Javascript,Jquery,我正在开发一个asp.net应用程序,其中我正在使用Jquery,我希望如果Jquery单击函数调用一次,则在页面加载之前不应再次调用它。单击功能代码如下所示 $("#plblAgreeProblem").click(function(){ var str = { problemID: $("#problemID").val(), empID : $("#empID").val() } $.ajax({

我正在开发一个asp.net应用程序,其中我正在使用Jquery,我希望如果Jquery单击函数调用一次,则在页面加载之前不应再次调用它。单击功能代码如下所示

  $("#plblAgreeProblem").click(function(){

      var str = {
            problemID: $("#problemID").val(),
            empID : $("#empID").val()
      }

      $.ajax({
                type: "POST",
                url: "<%= Url.Action("AgreeProblem", "Discussion")  %>",
                data: str,

                error: function(msg){
                    alert("error2" + msg);
                },
                success: function (msg) {

                    $("#ptxtDisAgreeProblem").empty();

                    $("#ptxtDisAgreeProblem").text(msg);

                }
            });
        })
$(“#plblAgreeProblem”)。单击(函数(){
var str={
problemID:$(“#problemID”).val(),
empID:$(“#empID”).val()
}
$.ajax({
类型:“POST”,
url:“”,
数据:str,
错误:函数(msg){
警报(“错误2”+消息);
},
成功:功能(msg){
$(“#ptxtproblem”).empty();
$(“#ptxtproblem”).text(msg);
}
});
})
对不起,英语不好。
感谢和问候

使用jQuery
one
功能:

$("#plblAgreeProblem").one('click', function(){ //...
描述:将处理程序附加到元素的事件。每个元素最多执行一次处理程序


在clikc处理程序的顶部添加以下内容:

$("#plblAgreeProblem").unbind('click');

其他答案通常都是正确的,但要解除事件绑定时请记住。只要用户点击它?还是等到ajax响应成功返回时

$("#plblAgreeProblem").click(function() {
    var $this = $(this);
    var str = {
        problemID: $("#problemID").val(),
        empID: $("#empID").val()
    }

    $.ajax({
        type: "POST",
        url: "<%= Url.Action("
        AgreeProblem ", "
        Discussion ")  %>",
        data: str,

        error: function(msg) {
            alert("error2" + msg);
        },
        success: function(msg) {

            $("#ptxtDisAgreeProblem").empty();

            $("#ptxtDisAgreeProblem").text(msg);

            // do this unbind here, after the call has been made successfully.
            $this.unbind('click');

        }
    });


})
$(“#plblAgreeProblem”)。单击(函数(){
var$this=$(this);
var str={
problemID:$(“#problemID”).val(),
empID:$(“#empID”).val()
}
$.ajax({
类型:“POST”,
url:“”,
数据:str,
错误:函数(msg){
警报(“错误2”+消息);
},
成功:功能(msg){
$(“#ptxtproblem”).empty();
$(“#ptxtproblem”).text(msg);
//在呼叫成功后,在此处解除绑定。
$this.unbind('click');
}
});
})