jquery可以做到这一点吗?值的弹出窗口

2023-09-30前端开发问题
1

本文介绍了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 对话框小部件 而不是一个实际的新窗口.这将使访问新值变得更容易,因为它位于同一窗口的 DOM 中.只需让关闭窗口的按钮的回调从对话框中包含的 DOM 元素中提取值并将其复制到表单上的目标 DOM 元素.

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可以做到这一点吗?值的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui中表单会自动刷新的问题
layui中表单会自动刷新的问题,因为用到layui的表单,遇到了刷新的问题所以记录一下: script layui.use(['jquery','form','layer'], function(){ var $ = layui.jquery, layer=layui.layer, form = layui.form; form.on('submit(tijiao)', function(data){ a...
2024-10-23 前端开发问题
262

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui中table列表 增加属性 edit="date",不生效怎么办?
如果你想在 layui 的 table 列表中增加 edit=date 属性但不生效,可能是以下问题导致的: 1. 缺少日期组件的初始化 如果想在表格中使用日期组件,需要在页面中引入 layui 的日期组件,并初始化: script type="text/javascript" src="/layui/layui.js"/scrip...
2024-06-11 前端开发问题
455