.wait()"undefined不是函数"

.wait() "undefined is not a function"

本文关键字:quot 函数 undefined wait      更新时间:2023-09-26

在显示模式警报框时,我一直试图阻止脚本继续运行。我确信我需要使用.wait((来等待ok按钮被点击。

这是显示我的对话并应用文本的代码。

function notify(heading,text){
   $("#errorHeading").empty();
   $( "#errorTxt").empty();
   var msg = $.mobile.changePage( "#confirm", { role: "dialog" } )+ $("#errorHeading").append(heading) + $( "#errorTxt" ).append("<p>"+text +"</p>" );
$("#confirmOK").wait('click');
}

这是HTML对话本身

    <div data-role="dialog" id="confirm" data-title="Are you sure?">
    <div data-role="content">
        <h3 class="confirmHead" id="errorHeading">???</h3>
        <p class="confirmMessage" id="errorTxt">???</p>
        <a href="#" id="confirmOK" data-role="button" data-theme="b" data-rel="back">OK</a>
    </div>
</div>

当我点击OK按钮关闭对话框时,我得到以下错误:

Uncaught TypeError: undefined is not a function client.js:393
notify client.js:393
$.ajax.success client.js:254
c jquery-1.10.2.js:3048
p.fireWith jquery-1.10.2.js:3160
k jquery-1.10.2.js:8235
n.onload.n.onreadystatechange

如果有人能提出解决方案,我将不胜感激。

提前感谢

编辑

我需要脚本停止并等待点击事件的原因是,如果我有一个通知,然后立即更改页面,那么通知在一秒钟内不会保持可见。

例如

notify("", "you may now log in as: " + $("#R_email").val()); //pause need it to pause here because the next line forces the notification to dissapear
window.location.replace("#changeUser"); 

问题是wait不是此上下文中的函数。因此,错误为undefined is not a function$('confirmOK').wait等于undefined,您将其作为函数调用。

JavaScript中没有waitsleep这样的东西。最接近的是setTimeout

您可以执行剩余的代码("wait(("之后的代码(,作为在单击"confirm"按钮时执行的回调函数,而不是等待按钮被单击。

例如:

    var callback = function () {
        window.close();
    }
    $("#confirmOK").click(callback);
    //Show your modal dialog;