$(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).id);
$( "#table_dialog_1" ).dialog('close');
})
});
$('#input_'+id).attr('value', $(this).html());
这与我想要的相近,但它仅根据对话框区域中表格的单击td's
文本通过,因为我需要的是对话框窗口的第一个 td
表格传递 input 标签
,second td
和 third
link 标签元素
。请参阅下面我在 fiddle 中的最后一张表格,当对话框窗口关闭时,它应该看起来像主页上的表格。
看这个FIDDLE
希望this是你要找的,我稍微重构了代码,将类 clickMe
添加到按钮,它使 id 变得不必要了。
JS代码
var clickedButton;
$(document).ready(function(){
$('.clickMe').click(function(){
clickedButton = this;
$( "#table_dialog_1" ).dialog();
});
$( '#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');
});
});
我是一名优秀的程序员,十分优秀!