我想使用Jquery创建基于XML或JSON数据的HTML表单,我还计划验证任何可能为空或不正确的表单字段.
我想知道是否有任何其他程序/功能动态生成这样的表单,并且是实现此目的的最佳方式.任何jquery小部件或库最适合工作示例将非常感激
以及在这种情况下最佳使用XML或JSON的原因并解释原因?
谢谢
小智 14
我发现其中一些可能会对你有所帮助:
从JSON模式生成表单:
从XML模式生成表单:
来自不同库的样本生成表单:
只是给你另一个选择,我创建了一个库:
https://github.com/brutusin/json-forms
JSON Schema到HTML表单生成器,支持动态子表单(即时解析).具有零依赖性的可扩展和可自定义的库.提供了Bootstrap附加组件
var bf = brutusin["json-forms"].create({
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"properties": {
"s1": {
"type": "string",
"title": "A string",
"description": "A string input"
},
"num1": {
"type": "integer",
"title": "A number",
"minimum": 1,
"maximum": 10,
"multipleOf": 3,
"description": "An integer multiple of `3`, between `1` and `10` (inclusive)"
},
"array1": {
"type": "array",
"title": "An array values",
"items": {
"type": "object",
"properties": {
"value": {
"type": "string",
"title": "Value"
}
}
}
}
}
});
var container = document.getElementById('container');
bf.render(container);
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href='https://cdn.jsdelivr.net/brutusin.json-forms/1.3.2/css/brutusin-json-forms.min.css'/>
<link rel="stylesheet" href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'/>
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/brutusin.json-forms/1.3.2/js/brutusin-json-forms.min.js"></script>
<script src="https://cdn.jsdelivr.net/brutusin.json-forms/1.3.2/js/brutusin-json-forms-bootstrap.min.js"></script>
<div id="container"></div>
<hr>
<button class="btn btn-primary" onclick="alert(JSON.stringify(bf.getData(), null, 4))">getData()</button> <button class="btn btn-primary" onclick="if (bf.validate()) {alert('Validation succeeded')}">validate()</button>
Run Code Online (Sandbox Code Playgroud)
更多http://brutusin.org/json-forms上的实例
归档时间: |
|
查看次数: |
55571 次 |
最近记录: |