Jquery添加克隆表单域 - 增加名称 [英] Jquery Adding cloning form fields - increment name
问题描述
我正在看这个小提琴
I'm looking at this fiddle http://jsfiddle.net/yezw6c51/1/ which does what I need to do with one exception.
When you load it has one Input field named 'phone_number'
When you click on Add phone number
you can add multiple rows/input fields as such :
Each new input field that is added has had it's field name incremented. eg : phone_number1, phone_number2 etc. This works fine.
But I'd like the text before each input field to also have the incremented value adding as well, so you end up with :
So the text description is incremented with the same value as the phone_number field.
ie: Phone Number 2 = phone_number2 etc
How do I do that ?
Thanks
Wrap your text with span
<span>Phone number :</span>
Then your can change only the text inside span
$(this).parent().find('span').text('Phone number ' + phone_number_form_index);
fiddle: http://jsfiddle.net/yezw6c51/16/
这篇关于Jquery添加克隆表单域 - 增加名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!