我想在调用$('#dialog')后暂停下面的javascript代码。dialog('open');直到用户响应此对话框。我用while循环,但它停止所有的JavaScript。我只想暂停这个功能。有任何想法吗?如何暂停和恢复JavaScript?
注:我不想将我的代码分成两个函数。我只是想,直到用户输入一些值暂停的JavaScript,就像一个提示
function sendSubComment(button){
form = button.parentNode
nodes= form.elements;
cmt = $(nodes.item(0)).val();
cmt = cmt.replace(/\n/g,"<br>");
title = $(nodes.item(1)).val();
for(i=0;i < nodes.length;i++){
nodes.item(i).disabled = 'true';
}
c = form.parentNode.parentNode;
if(checkUserLogin() == false){
$('#dialog').dialog('open');
//pause starts here
//return the values of user
//resume javascript
}
document.title = c.id;
$.post('index/phplibrary/action.php',{cmd:'insert_comment',cmt:cmt,title:title,id_topic:<?php echo $GLOBALS['id_topic']; ?>,id_parentComment:c.id,subcomment:'1'},function(result){
$.post('ajax/comments.php?cmd=get_subcomment&id_subcomment='+result,function(res){
extendMakeComment(form);
node = c.childNodes[3];
document.title = node.className;
t = document.createElement("DIV");
t.innerHTML = res;
t = t.childNodes[0];
$(t).hide();
node.appendChild(t);
$(t).show("slow");
form.reset();
for(i=0;i < nodes.length;i++){
nodes.item(i).disabled = '';
}
});
});
}
这个代码是如何创建对话框
$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
虽然已经太迟了..但是对于新的读者来说..我使用.. window.prompt(“message”,returnvaruable);它会暂停/停止所有的JavaScript在后台,当你点击..好的或从这些提示取消,它会让JavaScript继续。 – MFarooqi 2017-11-07 18:40:25