jQuery动态表单字段添加

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery动态表单字段添加相关的知识,希望对你有一定的参考价值。

I wrote this very quickly for a form I parse that allows a user to send a page to up to 5 friends. The script adds a click event to an image of a + sign beside an input box. When clicked if the user hasn't already added 5 friends to email, additional email boxes will be added.
  1. <script type="text/javascript" charset="utf-8">
  2. $(function() {
  3. var fieldCount = 1;
  4. $("#addFieldButton").click(function() {
  5. fieldCount++;
  6. if(fieldCount <= 5)
  7. {
  8. var fieldID = "recipient_email_" + fieldCount;
  9. $("#additionalEmails").append("<label for='"+fieldID+"'>Recipient Email "+fieldCount+": </label>"+
  10. "<input type='text' name='"+fieldID+"' " +
  11. "id='"+fieldID+"' size='30'><br />" );
  12. }
  13. else
  14. {
  15. alert("Maximum email fields reached.");
  16. }
  17. });
  18. });
  19. </script>

以上是关于jQuery动态表单字段添加的主要内容,如果未能解决你的问题,请参考以下文章

jQuery动态表单字段添加

Jquery -> php -> mysql 和动态表单字段

将 jQuery 验证规则添加到动态生成的表单元素时出错

如何使用 jquery 创建具有来自动态创建的表单字段的值的多维数组?

jquery验证动态表单输入的插件不起作用

如何将动态添加的表单字段发布到mysql数据库