Javascript jquery-将表的一行复制到另一行
我有这部分代码:Javascript jquery-将表的一行复制到另一行,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我有这部分代码: $('input[type=checkbox]').change(function() { if(this.checked) { var row = $(this).closest('tr').html(); $('#two').append('<tr>'+row+'</tr>'); } }); function clearSel(){ $(
$('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();
}
$('input[type=checkbox]')。更改(函数(){
如果(选中此项){
var row=$(this.closest('tr').html();
$('#two')。追加(''+行+'');
}
});
函数clearSel(){
$('input[type=checkbox]')。每个(函数(){
此项检查=错误;
});
$(“#2”).empty();
}
这段代码在本地文件夹上运行良好。当我把它放在xampp上的web应用程序上时,只有clearSel()函数起作用。表1内容是由返回行的php文件上的AJAX请求生成的。在访问页面的第一阶段,两个表都存在,但都是空的。我不明白为什么在xampp上失败。有什么建议吗?多谢各位
[编辑]超级用户提供的代码工作正常。我是新手,我对活动授权一无所知(我会学习)。谢谢你的回答 您可以在此处使用
事件委派
,检查下面更新的代码。$(document).on('change','input[type=checkbox]',function(){
如果(选中此项){
var row=$(this.closest('tr').html();
$('#two')。追加(''+行+'');
}
});
函数clearSel(){
$('input[type=checkbox]')。每个(函数(){
此项检查=错误;
});
$(“#2”).empty();
}
您可以跳过.html()
并直接将对象
附加到所需的div\two
!
$(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();
}