简体   繁体   English

要将jquery弹出窗口中的选定项目(通过复选框)复制到父页面

[英]Want to copy selected items (by checkbox) in a jquery popup to the parent page

I have a page that has a button, that when clicked opens up a jqueryui popup window. 我有一个带有按钮的页面,单击该按钮会打开一个jqueryui弹出窗口。

the window has a list of items, each with a checkbox beside it. 窗口中有一个项目列表,每个项目旁边都有一个复选框。

i want the selected items to be passed to the parent page when they hit the 'add' button on the popup. 我希望选定的项目在弹出窗口上单击“添加”按钮时传递到父页面。

The items should send back the values selected, and inject that into a textbox. 这些项目应发回所选的值,并将其注入到文本框中。

As @Adam mentioned, the form exists on the page already so you can easily read the values of the checkboxes. 正如@Adam所提到的,该表单已经存在于页面上,因此您可以轻松地读取复选框的值。

Here's some example code: 这是一些示例代码:

HTML 的HTML

<div id="some-form">
    <input type="checkbox" value="Option 1" />
    <input type="checkbox" value="Option 2" />
    <input type="checkbox" value="Option 3" />
</div>

jQuery jQuery的

$("#some-form").dialog({
    height:300,
    modal: true,
    buttons: {
        'Insert Checkbox Values': function() {
            // The following loops through the checked checkboxes
            $("input[type=checkbox]:checked", this).each(function() {
               alert($(this).val());
               // write AJAX insert method here using $.ajax or $.post
            });
            $(this).dialog('close');
        },
        Cancel: function() {
            $(this).dialog('close');
        }
    }
});

Please note that if you're using asp.net, the modal will be placed OUTSIDE of the <form> element which means you won't be able to access the controls. 请注意,如果您使用的是asp.net,则模式将放置在<form>元素的外面 ,这意味着您将无法访问控件。

There's an easy fix for that, simply append the modal to the form element like this: 有一个简单的解决方法,只需将模式附加到表单元素上,如下所示:

$("#some-form").parent().appendTo("form:first");

Hope this helps. 希望这可以帮助。

Marko 马可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM