简体   繁体   English

将表格行数据从对话框窗口传递到主页表格

[英]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.

相关问题 将数据从对话框窗口的选定行传递到主页 - Passed data on selected row from dialog window to main page 对话框窗口如何更新angularjs中的主表? - How the dialog window is updating the main table in angularjs? 将多行数据从表传递到模态 - Passing multiple row data from table to modal 使用Angular将数据从表传递到模式 - Passing a row of data from a table to a modal with Angular 将数据从 antdesign 表行传递到模态 - passing data from antdesign table row to modal 如何更新主表当前行的输入类型文本中的值从模态窗口表中获取值 - How to update the values in input type text of the current row of main table getting the values from modal window table 如何通过Vue将数据从表组件传递到另一个表组件,并使用编辑按钮传递表中的每一行 - how pass data from a table component in vue to another table component passing each row in the table with an edit button 从表中将值传递给其他 window - Passing the value to other window from table 从本机反应中的表格中选择一行并将所选行及其数据移动到另一页中的表格? - Selecting a row from a table in react native and moving the selected row with its data to a table in another page? jQuery:来自ajax的表数据的dialog()未显示 - jQuery: dialog() of table data from ajax not showing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM