如何使用 javascript/jQuery 生成动态表单?

发布于 2024-12-09 12:23:02 字数 144 浏览 0 评论 0原文

我需要根据服务器的 Ajax 响应动态生成整个 html 表单。作为响应,将会有输入类型、输入标签、验证(如果有)等信息。

表单最多始终有十个字段。

有没有 jQuery/ javascript 工具/插件来生成表单?

谢谢。

I need to generate an entire html form dynamically based on the Ajax response from server. In response there will be information like input type , input labels, validations if any etc.

The form at most will always have ten fields.

Is there any jQuery/ javascript tool/plugin to generate the form?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2024-12-16 12:23:02

Formation

从他们的示例中:

    value = {"key":"value"} "key" will be the value attribute and "value" will be the shown value of the element. If the array is constructed like {"value",value","value"} (without keys) then the value attribute of the input will be an auto-incremented number starting from 0.
options = {} See options table below.

$.fn.formation(options); [Create a form]
$.formation.addInput(options); [Append an input]
$.formation.addSelect(values,options); [Append a select]
$.formation.addTextarea(options); [Append a textarea]
$.formation.addCheckboxes(values,options); [Append an unordered list of checkboxes]
$.formation.addRadios(values,options); [Append an unordered list of radio buttons]
$.formation.addCaptcha(options); [Adds a captcha question to your form]
$.formation.addButton(options); [Append a button]
$.formation.setErrorMessages(options); [Set custom error messages for validation]

然而,这都是你可以使用 Jquery 轻松完成的事情,而且它是一个很好的学习经历,所以我建议你自己尝试一下。

Formation

From their example:

    value = {"key":"value"} "key" will be the value attribute and "value" will be the shown value of the element. If the array is constructed like {"value",value","value"} (without keys) then the value attribute of the input will be an auto-incremented number starting from 0.
options = {} See options table below.

$.fn.formation(options); [Create a form]
$.formation.addInput(options); [Append an input]
$.formation.addSelect(values,options); [Append a select]
$.formation.addTextarea(options); [Append a textarea]
$.formation.addCheckboxes(values,options); [Append an unordered list of checkboxes]
$.formation.addRadios(values,options); [Append an unordered list of radio buttons]
$.formation.addCaptcha(options); [Adds a captcha question to your form]
$.formation.addButton(options); [Append a button]
$.formation.setErrorMessages(options); [Set custom error messages for validation]

However, this is all stuff you can easily do with Jquery, and it is a good learning experience so I recommend trying it yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文