JSON jQuery输入值设置和获取表单值

  • 源码大小:13.04KB
  • 所需积分:1积分
  • 源码编号:19JP-3793
  • 浏览次数:1203次
  • 最后更新:2023年07月23日
  • 所属栏目:表单
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

一个简单易用的jQuery插件,允许您使用JSON设置和获取表单字段的值。

在从JSON生成动态表单或将所有输入值输出为JSON的表单生成器中可能很有用。

如何使用它:

1.在jQuery库之后加载jQuery输入值插件。

  1. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  2. <script src="/path/to/input-values.jquery.js"></script>

2.获取表单字段的所有值。这将返回一个包含所有表单字段及其值的JS对象。

  1. var values = $('form').inputValues();
  1. values = {
  2. "textInput":"jqueryscript",
  3. "numberInput":"",
  4. "passwordInput":"",
  5. "rangeInput":"50",
  6. "colorInput":"#000000",
  7. "dateInput":"",
  8. "monthInput":"",
  9. "timeInput":"",
  10. "textarea":"",
  11. "select":"",
  12. "selectMultiple":[],
  13. "radio":"",
  14. "checkbox":"",
  15. "file":""
  16. // ...
  17. }

3.从特定的表单字段中获取值。

  1. var value = $('form').inputValues('textInput');

4.根据您提供的数据填写表单字段。

  1. $('.form').inputValues({
  2. "textInput":"jqueryscript",
  3. "numberInput":"",
  4. "passwordInput":"",
  5. "rangeInput":"50",
  6. "colorInput":"#000000",
  7. "dateInput":"",
  8. "monthInput":"",
  9. "timeInput":"",
  10. "textarea":"",
  11. "select":"",
  12. "selectMultiple":[],
  13. "radio":"",
  14. "checkbox":"",
  15. "file":""
  16. // ...
  17. });
  1. $('form').inputValues('textInput', 'jqueryscript');

5.可能的插件选项。

  1. $().inputValues.config({
  2.  
  3. // the attribute that will be used as the key to match the elements of the form
  4. attr: 'name',
  5.  
  6. // determine whether to include disable fields
  7. includeDisabled: false,
  8. });

更新日志:

2021-12-01

  • 添加了香草JS版本

2021-11-15

  • 使现代化

预览截图