所以我有这个代码
$('input.clone').live('click', function(){
//put jquery this context into a var
var $btn = $(this);
//use .closest() to navigate from the buttno to the closest row and clone it
var $clonedRow = $btn.closest('tr').clone();
//append the cloned row to end of the table
//clean ids if you need to
$clonedRow.find('*').andSelf().filter('[id]').each( function(){
//clear id or change to something else
this.id += '_clone';
});
//finally append new row to end of table
$btn.closest('tbody').append( $clonedRow );
});
问题是,我克隆的每一行都被命名为_clone 我将如何编写此代码以便每次运行该函数时,它都会选择一个随机数或更理想的序列号附加到“_clone”的 id isstead
最佳答案
String(Math.floor(Math.random()*1000000))
将为您提供一个介于 0 和 999999 之间的字符串形式的随机数。
关于javascript - 克隆表行,将随机数或序号附加到 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1230436/