[英]jquery - Copy one row of table to another
I have this portion of code: 我有这部分代码:
$('input[type=checkbox]').change(function() {
if(this.checked) {
var row = $(this).closest('tr').html();
$('#two').append('<tr>'+row+'</tr>');
}
});
function clearSel(){
$('input[type=checkbox]').each(function() {
this.checked = false;
});
$("#two").empty();
}
This code works fine on a local folder. 此代码在本地文件夹上可以正常工作。 When I put it on a web app on xampp, just the clearSel() function works.
当我将其放在xampp的Web应用程序上时,只有clearSel()函数起作用。 The table one content is generated from a AJAX request on a php file which return rows.
表一的内容是根据php文件中的AJAX请求生成的,该文件返回行。 In first stage of accessing the page both tables exists, but are empty.
在访问页面的第一阶段,两个表都存在,但是为空。 I don't understand why on xampp fails.
我不明白为什么在xampp上失败。 Some suggestions?
有什么建议吗? Thank you.
谢谢。
[EDIT] The code provided of Super User works fine. [编辑]超级用户提供的代码可以正常工作。 I am newbie, i didnt know anything about event delegation(i will study) .
我是新手,我对事件委托一无所知(我将学习)。 Thank you for answer!!!!
谢谢你的答案!!!!
You can use event delegation
here, check updated code below.. 您可以在此处使用
event delegation
,请在下面查看更新的代码。
detail reference 详细参考
$(document).on('change', 'input[type=checkbox]', function() {
if(this.checked) {
var row = $(this).closest('tr').html();
$('#two').append('<tr>'+row+'</tr>');
}
});
function clearSel(){
$('input[type=checkbox]').each(function() {
this.checked = false;
});
$("#two").empty();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.