我的文本域的ID是字符串且格式如下:
id='fisher[27].man'
我想要克隆这个文本域并增加数字,将ID更改为fisher[28].man
,并将其添加到原有的文本域前面。
请问有没有使用jQuery轻松完成此操作的方法?
var existingId = $("#at textarea:last").attr('id');
var newCloned = lastTextArea.clone();
var newId = newCloned.attr('id');
//add the index number after spliting
//prepend the new one to
newCloned.prepend("<tr><td>" + newCloned + "</td></tr>");
有更简单的方法可以克隆、获取索引号、拆分和添加前缀。
我也尝试过使用正则表达式来完成这个任务。
var existingIdNumber = parseInt(/fisher[(\d+)]/.exec(s)[1], 10);
有人能帮我吗?