javascript - 动态创建的弹出窗口的问题
问题描述
当用户单击某个按钮时,我正在尝试使用一些输入字段动态创建一个弹出表单;当用户关闭弹出窗口时,我很难返回输入值。
在主窗体上,我有类似的内容:
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 函数等待用户单击弹出窗口上的保存按钮并获取答案值?
解决方案
推荐阅读
- r - 基于每列中的观察数的子集数据框
- python-3.x - 在python中使用生成器计算频率
- c# - ASP.NET MVC 4 项目中不存在布局
- javascript - 应用方法未在 javascript 中返回完整的数组值
- php - 在 null 上调用成员函数 close()
- angular - 如何使用Angular 7在输入字段中设置值
- python - Zapier 编写的代码:Python - 如何使其返回错误
- javascript - const 是否像 let 一样创建本地范围?
- javascript - 如何将选定的复选框行传递给函数
- json - 如何处理 Haskell 中 JSON 对象的可变性?