如何在不使用jQuery重新加载父窗口的情况下关闭弹出窗口 [英] How do I close the popup without reloading the parent window using jQuery

查看:74
本文介绍了如何在不使用jQuery重新加载父窗口的情况下关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的要求如下:

1.链接会打开一个弹出窗口。

2.在弹出窗口中会有一个搜索选项,搜索结果将显示在一个表格中。

3.表格的一列将被超链接,点击超链接将关闭弹出窗口并检索与超链接相关的值并将其显示到父窗口的文本字段。



我已编写以下代码来打开弹出窗口:



Hi,

My requirement is like below:
1. A link will open a popup window.
2. In the popup window there will be a search option and search result will be displayed in a table.
3. One column of the table will be hyperlinked and clicking on the hyperlink will close the popup window and retrieve the value related to the hyperlink and display it to the text field of parent window.

I have written following code to open the popup:

<script type="text/javascript">
    $(document).ready(function () {
        $("#lnkSupplier").live("click", function (e) {
            e.preventDefault(); //use this or return false
            var url = $(this).attr('href');
            $("#ListDialog").dialog({
                title: 'Find Supplier',
                autoOpen: false,
                resizable: false,
                height: 650,
                width: 700,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,`enter code here`
                open: function (event, ui) {
                    $(this).load(url);

                },
                close: function (event, ui) {
                    $(this).dialog('close');
                }
            });

            $("#ListDialog").dialog('open');
            return false;
        });
    });
<script/>





我编写了以下代码来获取Json数据并将它们放在弹出窗口的表格中。





I have written following code to get Json data and place them inside a table of the popup.

<script type="text/javascript">
    $(document).ready(function () {
        $('#btnSubmit').click(function () {
            $.getJSON('/Supplier/SupplierList/' + $('#CompanyName').val(), function (data) {
                var items = "<table class='gridtable'><tr><th class='CompanyName'>Company Name</th><th class='ContactName'>Contact Name</th><th class='ContactTitle'>Contact Title</th><th class='Country'>Country</th></tr>";
                $.each(data, function (i, supplier) {
                    items += "<tr><td>" + "<a id='" + supplier.SupplierID + "' href='Create/'" + supplier.SupplierID + " class='link' >" + supplier.CompanyName + "</a></td><td>"
                        + supplier.ContactName + "</td><td>"
                        + supplier.ContactTitle + "</td><td>"
                        + supplier.Country + "</td></tr>";
                });
                items += "</table>";
                $('#Suppliers').html(items);
            });
        })





当我点击表格栏中的'CompanyName'中的超链接时,弹出窗口将自动关闭。我编写了以下代码来关闭弹出窗口并检索父窗口的值。





When I click on a hyper link in the table column that is 'CompanyName' the popup will close automatically. I have written following code to close the popup and retrieve the the value for parent window.

var val = '';
        $("a.link").live('click', function (e) {
            e.preventDefault();
            val = this.id;
            $('#ListDialog').dialog('close');

        });





但是弹出窗口没有关闭。如果我删除e.preventDefault()语句,父窗口将刷新,其中已有的数据将消失。这是不对的!如何在从弹出窗口中检索值后关闭弹出窗口而不重新加载父窗口。



提前致谢。

Partha



But the popup is not closing. If I remove "e.preventDefault()" statement the parent window will get refreshed and data already available in it is disappeared. which is not right! How can I close the popup without reloading the parent window after retrieving value from the popup.

Thanks in advance.
Partha

推荐答案

(document).ready(function(){
(document).ready(function () {


#lnkSupplier)。live( click,function(e){
e.preventDefault(); // 使用此函数或返回false
var url =
("#lnkSupplier").live("click", function (e) { e.preventDefault(); //use this or return false var url =


this )。attr(' href');
(this).attr('href');


这篇关于如何在不使用jQuery重新加载父窗口的情况下关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆