[英]Getting ui element value of jquery dialog
我有兩個 web 表單,例如 webform1 和 webform2。 我將 webform2 稱為來自 webform1 的對話框。 我想在對話框的單擊按鈕事件上訪問 ui 元素(例如隱藏字段)。 當焦點位於對話框(webform2)上時,我可以在控制台中獲取隱藏的字段值,但是當我單擊對話框按鈕並在 JS 中執行按鈕事件的代碼時,隱藏字段值變得未定義。
$(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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.