当用户单击某些按钮时,我试图动态创建带有某些输入字段的弹出式窗体;当用户关闭弹出窗口时,我很难返回输入值。
在主表单上,我有类似的内容:
function GetAnswers() {
var answers=ShowPrompts();
return answers;
}
function ShowPrompts() {
var answer="";
var popup=window.open('','PopupForm');
TextControl= popup.document.createElement("INPUT");
TextControl.setAttribute("type", "text");
TextControl.value="";
TextControl.setAttribute("id", 'idInput1');
popup.document.body.appendChild(TextControl);
var ButtonControl = popup.document.createElement("button");
var TextNode = popup.document.createTextNode("Save");
ButtonControl.appendChild(TextNode);
ButtonControl.style.float="right";
popup.document.body.appendChild(ButtonControl);
ButtonControl.onclick = function(){
InputControl=popup.document.getElementById('idInput1');
answer=InputControl.value;
}
return answer;
}
问题是仅当用户单击“保存”按钮时才设置“答案”;因此,在调用ShowPrompts时,它仅返回“”。如何使GetAnswers函数等待用户单击弹出窗口上的“保存”按钮并获得答案值?