我有两个webform,例如webform1和webform2,我从webform1中调用webform2作为对话框,我想在对话框的点击按钮事件中访问ui元素(例如隐藏字段)。当焦点在对话框(webform2)上时,我可以在控制台中得到隐藏的filed值,但是当我点击对话框按钮,JS中的代码执行按钮事件时,隐藏的filed值变成了未定义的。
$(function () {
$("#dialog").dialog({
autoOpen: false,
modal: true,
width: 950,
title: "Add Lines to Manual Invoice",
close: function () {
$(this).dialog("close");
},
buttons: {
okay: function () {
console.log($('#HiddenField1').val()) // This is undefined while i want to access webform2 vlaue
$(this).dialog("close");
}
},
show: {
effect: "slide",
duration: 1500
}
});
$("#opener").click(function () {
$("#dialog").dialog('open');
return false;
});
});
我在iframe标签中加载了webform2,如下图所示。
<button id="opener">open the dialog</button>
<div id="dialog" title="Dialog Title"><iframe style="border: 1px;height:700px;width:930px;" src="WebForm2.aspx"></iframe></div>
我已经用下面一行代码解决了这个问题。
$(this).find('iframe').contents().find('[id="HiddenField1"]').val()