简体   繁体   English

jQuery-调用模态对话框后如何继续执行脚本

[英]JQuery - How can I carry on with script after call to modal dialog

I have a script that calls a modal dialogue to get some values from the user. 我有一个脚本,该脚本调用模式对话以从用户那里获取一些值。 if is use prompt the user enters a single value and control is passed back to the script. 如果使用提示,则用户输入一个值并将控制权传递回脚本。

However, if I open a dialogue it does not return control to the next command in the script. 但是,如果打开对话框,则不会将控制权返回到脚本中的下一个命令。

Can anyone show me where I am going wrong? 谁能告诉我我要去哪里错了?

This code works (note getWeight call to prompt) 此代码有效(请注意getWeight调用以提示)

$('#scancodebox').change(function () {
        var barcode = '';
        if (this.value.length > 0) {
            barcode = this.value;
            var scancountry = barcode.substring(0, 2);
            var scanherd = barcode.substring(2, 8);
            var scananimal = barcode.substring(8, 14);
            var scandate = barcode.substring(14, 22);
            var scandobday = barcode.substring(14, 16);
            var scandobmonth = barcode.substring(16, 18);
            var scandobyear = barcode.substring(18, 22);
            var scansex = barcode.substring(22, 23);
            var scanbreed = barcode.substring(23);
            var getWeight = prompt("Enter Weight");            

            var scandob = scandobyear + "/" + scandobmonth + "/" + scandobday
            //****************************************************************
            // Calculate Days
            //****************************************************************
            var utcToday = new Date();
            var utcDob = new Date(scandobyear, scandobmonth, scandobday);
            var _MS_PER_DAY = 1000 * 60 * 60 * 24;
            var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
            var daysold = Math.round(Math.abs((utcDob.getTime() - utcToday.getTime()) / (oneDay)));
            var scanmoveon = utcToday.getFullYear() + "/" + utcToday.getMonth() + "/" + utcToday.getDate()
            //****************************************************************

            //var scanCountry = substring(barcode, 1, 2);
            //alert(scanCountry);
            //this.value = '';

            var grid = $("#grdSPL").data("kendoGrid");
            grid.dataSource.add({
                Country: scancountry,
                HerdNumberId: scanherd,
                DOB: scandob,
                MoveOn: scanmoveon,
                AnimalId: scananimal,
                BreedId: scanbreed,
                Weight: getWeight,
                NotifyCTS: 1,
                Age: daysold,
                Grade: 2,
                DayTag: Math.floor(Math.random() * 250) + 1,
                Sex: scansex
            });
        }
    }

This shows popup but on close does not continue. 这将显示弹出窗口,但关闭后不会继续。

  $('#scancodebox').change(function () {
        var barcode = '';
        if (this.value.length > 0) {
            barcode = this.value;
            var scancountry = barcode.substring(0, 2);
            var scanherd = barcode.substring(2, 8);
            var scananimal = barcode.substring(8, 14);
            var scandate = barcode.substring(14, 22);
            var scandobday = barcode.substring(14, 16);
            var scandobmonth = barcode.substring(16, 18);
            var scandobyear = barcode.substring(18, 22);
            var scansex = barcode.substring(22, 23);
            var scanbreed = barcode.substring(23);
            //var getWeight = prompt("Enter Weight");
            var retval = $("#dialog-modal").dialog("open");

            var scandob = scandobyear + "/" + scandobmonth + "/" + scandobday
            //****************************************************************
            // Calculate Days
            //****************************************************************
            var utcToday = new Date();
            var utcDob = new Date(scandobyear, scandobmonth, scandobday);
            var _MS_PER_DAY = 1000 * 60 * 60 * 24;
            var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
            var daysold = Math.round(Math.abs((utcDob.getTime() - utcToday.getTime()) / (oneDay)));
            var scanmoveon = utcToday.getFullYear() + "/" + utcToday.getMonth() + "/" + utcToday.getDate()
            //****************************************************************

            //var scanCountry = substring(barcode, 1, 2);
            //alert(scanCountry);
            //this.value = '';

            var grid = $("#grdSPL").data("kendoGrid");
            grid.dataSource.add({
                Country: scancountry,
                HerdNumberId: scanherd,
                DOB: scandob,
                MoveOn: scanmoveon,
                AnimalId: scananimal,
                BreedId: scanbreed,
                Weight: getWeight,
                NotifyCTS: 1,
                Age: daysold,
                Grade: 2,
                DayTag: Math.floor(Math.random() * 250) + 1,
                Sex: scansex
            });
        }
    }

Thanks in advance. 提前致谢。

Ron 罗恩

when you call open dialog it's not wait for getting value from user and it's continue to run next command. 当您调用打开对话框时,它不等待用户获取价值,而是继续运行下一个命令。 so you have to wait for closing the dialog and do the rest your code. 因此,您必须等待关闭对话框并执行其余的代码。 try use Bootstrap Dialog ( https://nakupanda.github.io/bootstrap3-dialog/ ) and in callback you can do the rest. 尝试使用Bootstrap对话框( https://nakupanda.github.io/bootstrap3-dialog/ ),然后在回调中完成其余工作。

i hope it will be useful for you. 我希望它将对您有用。

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

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