jQuery可以做到这一点?价值弹出窗口 [英] jquery can do this? popup window for value

查看:78
本文介绍了jQuery可以做到这一点?价值弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户从父窗口单击按钮时,我使用JavaScript打开了一个新窗口(子窗口).

I used JavaScript to open a new window(child) when user clicks on button from parent window.

在新窗口(子窗口)上,我有文本框和按钮,我需要获取文本框的值并在用户单击按钮时传递到父窗口,而在关闭子窗口时,我需要将更新后的值插入父窗口中窗口(不刷新父窗口),这样我可以在父窗口的某些隐藏字段/标签中显示我的值,该怎么办?

On new window(child), I have textbox and button, I need to get the value of the textbox and pass to parent window when user clicks on button, while closing the child window, I need the updated value inserted into parent window (without refreshing parent window) so I can display my value to some hidden field/ label of the parent window , how can I do that?

1-父窗口具有按钮,单击的子窗口已打开 2-子窗口具有文本框和按钮,单击按钮后,子窗口将发布到服务器以更新数据库,然后将文本框的值传递给父窗口而不刷新父窗口,然后关闭子窗口.

1- parent window has button, clicked child window opened 2- child window has textbox and button, when button clicked, child will do a post to server to update database, then pass the value of textbox to parent window without refreshing parent window, and close child window.

我该怎么做?可以使用简单的JavaScript完成吗? 如果我使用jquery进行操作,我会获得更多好处吗? 谁能建议我该怎么做?

How can I do that? Is it can be done with simple JavaScript? If I do it using jquery, will I have more benefit? Could anyone advice how can I do it?

推荐答案

我建议使用jQuery

I would suggest using the jQuery dialog widget instead of an actual, new window. This will make it easier to access the new value as it's in the same window's DOM. Just have the callback from the button that closes the window extract the value from the DOM element contained in the dialog and copy it to the target DOM element on the form.

$('#popupDialog').dialog({
     modal: true,
     autoOpen: false,
     buttons: {
          'Cancel': function() {
                       $(this).dialog('close');
                    },
          'Accept': function() {
                       $('#mainForm input#target').val( $(this).find('#widgetName').val() );
                       $(this).dialog('close');
                    }
});

$('#popupButton').click( function() {
   $('#popuDialog').dialog('open');
});


<div id="popupDialog" title="Input a new widget name">
  <p>
     <label for="widgetName">Please input a new widget name:</label>
     <input type="text" id="widgetName" />
  </p>
</div>

这篇关于jQuery可以做到这一点?价值弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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