Jquery 无法复制单元格值
单击一行中的复制链接后,我需要创建另一行并将其所有内容复制到新行。这是我的代码:Jquery 无法复制单元格值,jquery,Jquery,单击一行中的复制链接后,我需要创建另一行并将其所有内容复制到新行。这是我的代码: addNewInlineRow(sid, idToUse); // this creates a new row with empty values //this copies the value from old row to new row $("#"+rowId+ " td").each(function(index){ $("#"+idToUse+ " td").get(index).text($(
addNewInlineRow(sid, idToUse); // this creates a new row with empty values
//this copies the value from old row to new row
$("#"+rowId+ " td").each(function(index){
$("#"+idToUse+ " td").get(index).text($(this).text());
});
但是这个代码不起作用。有什么建议吗?由于创建TR id的现有复杂逻辑,我无法克隆整个TR 使用.get()
检索DOM元素时,它不是jQuery对象,因此不能使用.text()
设置文本值。尝试:
$("#"+idToUse+ " td").get(index).innerHTML = $(this).text();
使用.get()
检索DOM元素时,它不是jQuery对象,因此不能使用.text()
设置文本值。尝试:
$("#"+idToUse+ " td").get(index).innerHTML = $(this).text();
当您想要从任何容器(如
div)检索值时,span
您必须在jquery中使用.html()
请尝试以下代码:
$("#"+idToUse+ " td").get(index).html($(this).html());
当您想要从任何容器(如
div)检索值时,span
您必须在jquery中使用.html()
请尝试以下代码:
$("#"+idToUse+ " td").get(index).html($(this).html());
您可以使用
clone
方法获取tr
的克隆并将其附加到表tbody中
试试这个
function addNewInlineRow(sid, idToUse){
var $clone = $("#"+sid).clone();
$clone.attr("id", idToUse);
//Now append the clone to table
$("table").append($clone);
}
您可以使用
clone
方法获取tr
的克隆并将其附加到表tbody中
试试这个
function addNewInlineRow(sid, idToUse){
var $clone = $("#"+sid).clone();
$clone.attr("id", idToUse);
//Now append the clone to table
$("table").append($clone);
}
您仍然可以克隆整个tr,然后更新需要更新的部分(即ID):
您仍然可以克隆整个tr,然后更新需要更新的部分(即ID):
你试过克隆tr吗?你试过克隆tr吗?你比我快,因为我拉小提琴慢。这里是为了防止有人停在这一页:你比我快,因为我拉小提琴太慢了。如果有人在本页面停留,请点击此处: