使用jQuery在父窗口和子弹出窗口之间传递数据
我有以下HTML
Affiliate Party
和以下Javascript / jQuery
$(".PartyLookup").after(""); $(".PartyLookupToggle").click(function () { window.open("PartySearch.aspx", "PartySearch", "width=400,height=50"); return false; });
我需要能够使用class =“PartyLookup”标记任何PartyId输入字段,以便它将修改DOM并将图像包含在输入字段旁边。 弹出窗口返回数据以填充隐藏字段和文本字段,但由于click()是通用的,我需要传递输入字段的ID。 我不知道该怎么做。 有什么建议?
父页面上的脚本:
$(".PartyLookupToggle").click(function () { var id = $(this).prev().prev().attr("id"); var name = $(this).prev().attr("id"); var url = "PartySearch.aspx?id=" + id + "&name=" + name; window.open(url, "PartySearch", "width=400,height=50"); return false; });
子页面上的脚本:
// Get the values from the URL using the jquery.query plug-in var id = $.query.get("id"); var name = $.query.get("name"); // Get the values from the drop down var newPartyId = $("#ddlMatchingParties").val(); var newPartyName = $("#ddlMatchingParties option:selected").text(); // Set them to the parent window window.opener.$("#" + id).val(newPartyId); window.opener.$("#" + name).val(newPartyName); // Close the popup window.close();
使用jQuery非常简单,在子窗口(弹出窗口)中调用父窗口对象:
$("#txtCodCliente", opener.window.document).val("VALUE TO "); //assign $("#btnSelCliente", opener.window.document).click();
使用opener.window.document
我们告诉jQuery该对象在窗口中打开弹出窗口。
看看这篇教学文章: http : //www.plus2net.com/javascript_tutorial/window-child3.php
基本上,您需要在子窗口的表单中执行此操作。 你会传递一个这样的值:
opener.document.f1.p_name.value="Any value";
其中f1
是父窗口中表单的ID, p_name
是表单中字段的名称。
获得父级字段中的值后,您可以随意执行任何操作。
编辑:
要将信息传递给子窗口,最简单的方法可能是通过查询字符串,然后从子窗口中读取查询字符串。 在这种情况下,可能是这样的:
$(".PartyLookupToggle").click(function () { window.open("PartySearch.aspx?id=" + $(this).prev().attr('id'), "PartySearch", "width=400,height=50"); return false; });
- 从C#后面的ASP.NET代码调用jQuery函数
- ASP.NETvalidation失败时更改文本框的css类
- 显示警告框,其中包含文本字段
- 提交按钮不会触发服务器端代码
- 为什么Asp.Net MVC 5将@ Scripts.Render(“〜/ bundles / jquery”)放在_Layout.cshtml的底部?
- jQuery DatePicker:当日期字段为12-31-9999时,currentDate不起作用
- 如何将表单数据发布到API控制器
- jquery.validate似乎不适用于某些输入,其中name值包含一个点,即RegisterModel.Pssword
- 编辑内部html页面,打开jQuery对话框