Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery分配html并从表单中获取值_Jquery_Jquery Ui Dialog - Fatal编程技术网

使用jquery分配html并从表单中获取值

使用jquery分配html并从表单中获取值,jquery,jquery-ui-dialog,Jquery,Jquery Ui Dialog,我们有以下形式的jQuery对话框: $("<div></div>").dialog({ buttons: myButtons, close: function(event, ui) { $(this).remove(); }, resizable: false, title: title, modal: true, width: my_width }).html(message); 当信息仅仅是文本时,这非常有效。但是,

我们有以下形式的jQuery对话框:

$("<div></div>").dialog({
    buttons: myButtons,
    close: function(event, ui) { $(this).remove(); },
    resizable: false,
    title: title,
    modal: true,
    width: my_width
}).html(message);
当信息仅仅是文本时,这非常有效。但是,现在我们希望在消息中包含一个输入字段。访问输入字段的值时遇到问题

信息如下:

'Enter some text.<br/><br/><form><input id="field1"></input></form>'
我们的问题是,当我们试图使用document.getElementById'field1.value访问输入字段的值时,DOM元素显然不存在,并且我们还没有找到访问用户条目的方法


在用户提交对话框后,我们需要做什么才能获得该元素的值?

如果在运行代码之前关闭对话框,您将无法获得该值,因为您正在调用$this.remove,它将从DOM中删除元素。您需要在关闭处理程序中获取值。

如果在运行代码之前关闭对话框,您将无法获取值,因为您正在调用$this.remove,它将从DOM中删除元素。您需要在close handler中获取值。仅供参考,这里没有。输入字段是自动关闭的。@MikeMcCaughan-你一针见血。请回答这个问题而不是发表评论,这样我就可以相信这个答案了。