.wait()"undefined不是函数"
.wait() "undefined is not a function"
在显示模式警报框时,我一直试图阻止脚本继续运行。我确信我需要使用.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中没有wait
或sleep
这样的东西。最接近的是setTimeout
。
您可以执行剩余的代码("wait(("之后的代码(,作为在单击"confirm"按钮时执行的回调函数,而不是等待按钮被单击。
例如:
var callback = function () {
window.close();
}
$("#confirmOK").click(callback);
//Show your modal dialog;
相关文章:
- Javascript复选框函数:;缺少:在属性id之后"
- 为什么spyOn"停止函数“”的所有执行;Jasmine(要求澄清Jasmine 2.2间谍文件)
- 得到"未定义不是函数“;使用显示原型图案时出错
- 什么是"!函数(){}〃;javascript中的mean/do
- 我对“;返回true"嵌套函数内部;t工作
- 为什么"构造函数是一种特殊情况;
- 如何分解jQuery"toggle”;函数转换为separate“;显示“;以及“;隐藏“;功能
- "这个“;函数的作用域无效
- "未定义不是函数“;错误jQuery,.replaces,scrollTop
- 我收到一个类型错误,其中包含-"$不是函数“;使用noConflict时
- 传递带有符号“”的字符串变量'"到函数
- "撤消”;Javascript中的DOM操作函数
- JavaScript美学:;函数foo(){}"vs“;var foo=函数(){}"AMD功能
- 得到"TypeError:对象不是函数“”;在forEach循环中使用超级测试/超级代理时
- “=>"在javascript中定义函数的语法及其意义
- "可变变量可从闭包“”访问;在传递给Array.prototype.every的函数中
- "未捕获的类型错误:未定义的不是函数“;当向输入字段添加值时
- "对象不是函数“;当将Node.js HTTP服务器对象传递给Socket.IO时
- AngularJS'ng:areq错误参数"{controller}不是函数“;,CodeIgnite
- 页面不可滚动,其中ng include=“”;函数()"-该代码已不再使用