按钮单击是gettint在Javascript文件(MVC)中触发变量次数 [英] button click is gettint fired variable number of times in Javascript file(MVC)

查看:91
本文介绍了按钮单击是gettint在Javascript文件(MVC)中触发变量次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javacript文件中点击了一个按钮,通过它我正在进行ajax调用。



奇怪的是,当我通过localhost运行应用程序时,它工作正常精细。但是当我发布它,然后尝试运行时,这个按钮事件被触发可变次数,有时两次有时两次。但大多数是两次。在按钮事件中,我发出警报作为验证。此外,这个按钮点击事件进入document.ready函数。



代码片段是:



 $( #btnUpdate)。click(function(){ 
if ($( #drpstatusEdit option :selected)。text()== ' Closed'){
var OffshoreResourceIds = ' ';
$(' #drpOffshoreUsersEdit:selected')。each(function(i,selected){
OffshoreResourceIds = OffshoreResourceIds + ' ,' + $(selected).val();
});

如果 ($( #txtTicketDesc)。val()== ' '
alert(' description不能为空);
else searchUserWithoutCriterion();
}
else {
updateTickets();

}
getTicketCount();
});

函数updateTickets(){
// 一些带警报的代码
alert( );
}







如何让它只被解雇一次,因为它工作正常通过localhost运行。(我不希望按钮取消绑定)。

解决方案

#btnUpdate)。click(function(){
if


< blockquote>( #drpstatusEdit option:selected)。text()== ' Closed'){
var OffshoreResourceIds = < span class =code-string>' ';


' #drpOffshoreUsersEdit:selected')。each(function(i,selected){
OffshoreResourceIds = OffshoreResourceIds + ' ,' +


I have a button click in javacript file through which i am making a ajax call.

strange is that, when i am running application through localhost, it working fine. But when i publish it, then try to run, this button event fired variable number of times, sometimes twice sometime thrice.But mostly twice. In button event i am giving a alert as validation. Moreover,this button click event come in document.ready function.

The code snippet is:

$("#btnUpdate").click(function () {
    if ($("#drpstatusEdit option:selected").text() == 'Closed') {
        var OffshoreResourceIds = '';
        $('#drpOffshoreUsersEdit :selected').each(function (i, selected) {
            OffshoreResourceIds = OffshoreResourceIds + ',' + $(selected).val();
        });

        if ($("#txtTicketDesc").val() == '')
            alert('description cannot be blank');
        else searchUserWithoutCriterion();
    }
    else {
        updateTickets();

    }
    getTicketCount();
});

function updateTickets() {
    //some code with alert
    alert("something");
}




How to make this to get fired only once as it working fine when running through localhost.(i dont want button to unbind).

解决方案

("#btnUpdate").click(function () { if (


("#drpstatusEdit option:selected").text() == 'Closed') { var OffshoreResourceIds = '';


('#drpOffshoreUsersEdit :selected').each(function (i, selected) { OffshoreResourceIds = OffshoreResourceIds + ',' +


这篇关于按钮单击是gettint在Javascript文件(MVC)中触发变量次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆