Jquery添加克隆表单域 - 增加名称 [英] Jquery Adding cloning form fields - increment name

查看:183
本文介绍了Jquery添加克隆表单域 - 增加名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看这个小提琴


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆