我想要用一个新的值替换name属性的一部分,这个新的值依赖于原始值。name属性的值为:timeslots[timeslot_1][start]
如何将值“timeslot_1”递增为“timeslot_2”,并将原始值替换为此值?
cloneElm包含两种类型的元素(input和select) - 我希望能够在循环中捕获这两种元素。
到目前为止我写出的代码:
$(cloneElm).children('span').children('input').each(function(id) {
var newName = $(this).attr('name').replace('timeslot_1', 'timeslot_2');
$(this).attr('name', newName);
});
谢谢