[英]Passing table row data from dialog window to main page table
This is table on main page : 这是主页上的表:
<table>
<th>Apple</th>
<th>Ball</th>
<tr>
<td><input type="text" /></td>
<td><input type="button" /><a href="#"></a></td>
</tr>
<tr>
<td><input type="text" /></td>
<td><input type="button" /><a href="#"></a></td>
</tr>
</table>
This is table on window dialog : 这是窗口对话框上的表格:
<table>
<th>Apple on Dialog</th>
<th>Ball on Dialog</th>
<tr>
<td>A1</td>
<td>A2</td>
<td>A3</td>
</tr>
<tr>
<td>B1</td>
<td>B2</td>
<td>B3</td>
</tr>
</table>
see this FIDDLE , not for working code but for wanted result page,because I don't know how to create window dialog on jsfiddle so bare with my fiddle. 看到这个FIDDLE ,而不是工作代码,而是想要的结果页面,因为我不知道如何在jsfiddle上创建窗口对话框,所以我的小提琴光秃秃的。 Thanks everyone. 感谢大家。
Please check this JSFIDDLE 请检查此JSFIDDLE
You have to save/pass the clicked btn's identity to the dialog so that it knows where to copy and paste the content. 您必须将单击的btn的身份保存/传递到对话框,以便对话框知道在何处复制和粘贴内容。 Hope the jsfiddle gives you some idea 希望jsfiddle给您一些想法
$(document).ready(function(){
$('#1, #2').click(function(){
window.clickedbtnid = $(this).attr('id');
$( "#table_dialog_1" ).dialog();
});
$( "#table_dialog_1" ).find('td').click(function(){
$('#'+window.clickedbtnid).parent().prev().find('input').val($(this).text());
$( "#table_dialog_1" ).dialog('close');
})
});
You need to add a click event for buttons on the first table and assign the TD
text to the input on the same row of the button. 您需要为第一个表上的按钮添加click事件,并将TD
文本分配给按钮同一行上的输入。
$(document).ready(function(){
$('#1, #2').on('click', function(){
$("#table_dialog_1").dialog();
var id = $(this).attr('id');
$('#table_dialog_1 td').unbind('click').on('click', function(){
console.log('#input_'+id);
$('#input_'+id).attr('value', $(this).html());
$('#table_dialog_1').dialog('close');
});
});
});
I unbind
the click event inside on the first click event to remove previous events. 我在第一个click事件上unbind
了内部的click事件的unbind
,以删除以前的事件。
See the complete working example 查看完整的工作示例
If you need to work with popup instead of dialog, follow this simple tutorial 如果您需要使用弹出窗口而不是对话框,请按照以下简单教程进行操作
UPDATE UPDATE
In order to use window.open()
, in the parent window put this javascript code: 为了使用window.open()
,在父窗口中放置以下javascript代码:
$('.clickMe').click(function(){
clickedButton = this;
$( "#table_dialog_1" ).dialog();
window.button_clicked_id = $(this).attr('id');
});
And this code in the child window. 并将此代码放在子窗口中。
var the_button = window.opener.button_clicked_id;
var clickedButton = $('#'+the_button, window.opener.document);
$( '#table_dialog_1 tr').click(function(){
var tds = $(this).children();
$(clickedButton).parent().prev().find('input').val(tds.eq(0).html());
$(clickedButton).next('a').text(tds.eq(2).html()+','+tds.eq(1).html());
$( "#table_dialog_1" ).dialog('close');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.