开发者

Unable to copy cell values

On click of the Copy link in a row, I need to create another row and copy all its contents to the new row. This is the code I have:

addNewInlineRow(sid, idToUse); // this creates a new row wi开发者_如何学Pythonth empty values
//this copies the value from old row to new row
$("#"+rowId+ " td").each(function(index){
    $("#"+idToUse+ " td").get(index).text($(this).text());
});

But this code is not working. Any suggestions? I cannot clone the entire TR due to existing complex logic for creating TR id!!


You can use clone method to get the clone of tr and append it to the table tbody.

Try this

function addNewInlineRow(sid, idToUse){
   var $clone = $("#"+sid).clone();
   $clone.attr("id", idToUse);

   //Now append the clone to table
   $("table").append($clone);
}


When you use .get() you're retrieving the DOM element, it is not a jQuery object, therefore you can not use .text() to set the text value. Try:

$("#"+idToUse+ " td").get(index).innerHTML = $(this).text();


You can still clone the entire tr and then update the parts that need updating (i.e. the ID):

function addNewInlineRow(sid, idToUse){
   $('#' + sid).clone().attr('id', idToUse).appendTo('table');
}


When you want to retrieve the values form any containers like div,span

You must use the .html() in jquery.

Try the blow code:

 $("#"+idToUse+ " td").get(index).html($(this).html());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜