javascript - 如何将值从子弹出窗口填充到父窗口?
问题描述
我有输入字段,我想从带有表记录的弹出窗口中填充。当我单击选择按钮填充记录时,我只得到第一条记录。即使我选择了最后一条记录。
我有两个单独的文件。文件 A 和文件 B。文件 A 激活文件 B 的弹出窗口。文件 A
<div class="input-group">
<input type="text" class="form-control" name="munit">
<span class="input-group-addon success" onclick="myFunction()"> <span class="glyphicon glyphicon-ok"></span></span>
</div>
<input type="text" id="managementu" readonly="readonly" />
<input type="text" id="department" readonly="readonly" />
<input type="text" id="division" readonly="readonly" />
文件 B。
<table class="table">
<thead>
<tr>
<th>Management Unit</th>
<th>Department</th>
<th>Division</th>
<th>Action</th>
</tr>
</thead>
<tbody id="myTable">
<?php foreach ($records as $row){?>
<tr>
<td><?php echo $rows['Description']; ?></td>
<td><input type="text" id="dept" value="<?php echo $rows['Department_Description']; ?>"></td>
<td><input type="text" id="divi" value="<?php echo $rows['Division_Description']; ?>"/></td>
<td><input type="text" id="reg" value="<?php echo $rows['Region_Description']; ?>"/></td>
<td><input type="text" id="dist" value="<?php echo $rows['District_Description']; ?>"/></td>
<td><button onclick="copyFunc<?php echo $rows['Code']; ?>()" >Select</button></td>
</tr><?php }?>
<script>
function copyFunc() {
if (window.opener != null && !window.opener.closed) {
var division = window.opener.document.getElementById("division");
division.value = document.getElementById("divi").value;
var department = window.opener.document.getElementById("department");
department.value = document.getElementById("dept").value;
var region = window.opener.document.getElementById("region");
region.value = document.getElementById("reg").value;
var district = window.opener.document.getElementById("district");
district.value = document.getElementById("dist").value;
}
window.close();
}
</script>
<script>
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myTable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
</tbody>
</table>
</body>
</html>
解决方案
您只需要修改它以获得唯一的 ID(然后多次复制 JS 代码,如果您仍想使用 ID 访问字段),
推荐阅读
- redux - Redux createAsyncThunk 的进度条?
- django - Django 和 APScheduler 不在 IIS 服务器上运行
- git - 如何列出已经完全包含在 HEAD 中的旧分支
- r - R tsibble 添加对自定义索引的支持
- python - 如何使用 fastapi 和 vue 上传文件?我收到错误无法处理 422
- java - 为什么 HashMap(和其他类)的 OpenJDK 实现中的值使用位移进行初始化?
- tensorflow - TensorFlow 分类标签 0 和 1
- python - 用户定义函数在 Python 中不起作用
- python - 如何在 Python 中将输入数据动态共享到并行进程
- javascript - 在 oracle apex 中每隔几分钟执行一次 plsql 代码