【发布时间】:2015-12-30 01:27:53
【问题描述】:
我的 textarea 的 id 是字符串并且是这种格式
id='fisher[27].man'
我想克隆 textarea 并增加数字并将 id 设为 fisher[28].man 并将其添加到现有 textarea。
有没有办法用 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);
谁能帮我解决这个问题?
【问题讨论】:
标签: javascript