0

我正在使用 JQuery dForm 插件来创建表单。它适用于以下代码:

$("#myform").dform({
            "action" : "index.html",
            "method" : "get",
            "html" :
            [
                {
                    "type" : "p",
                    "html" : "You must login"
                },
                {
                    "name" : "username",
                    "id" : "txt-username",
                    "caption" : "Username",
                    "type" : "text",
                    "placeholder" : "E.g. user@example.com"
                },
                {
                    "name" : "password",
                    "caption" : "Password",
                    "type" : "password"
                },
                {
                    "type" : "submit",
                    "value" : "Login"
                }
            ]
        });

但是,如果我将表单定义移动到 JSON 文件中,例如:

"action" : "index.html",
            "method" : "get",
            "html" :
            [
                {
                    "type" : "p",
                    "html" : "You must login"
                },
                {
                    "name" : "username",
                    "id" : "txt-username",
                    "caption" : "Username",
                    "type" : "text",
                    "placeholder" : "E.g. user@example.com"
                },
                {
                    "name" : "password",
                    "caption" : "Password",
                    "type" : "password"
                },
                {
                    "type" : "submit",
                    "value" : "Login"
                }
            ]

并尝试从 json 加载表单定义:

$("#myform").dform('test.json', function(data) {
          this //-> Generated $('#myform')
          data //-> data from path/to/form.json
        });

表单不加载。我是否需要在 JSON 文件或代码中添加其他内容?

任何帮助深表感谢。

谢谢,卡洛斯

4

1 回答 1

0

这是 JSON 中的一个问题。基本上一个 JSON DForm 定义可以是:

{"id":"form","action":"","html" :[{"type" : "p","html" : "You must login"},{"name" : "username","id" : "txt-username","caption" : "Username","type" : "text","placeholder" : "E.g. user@example.com","onkeypress":"myKeypress"},{"name" : "password","caption" : "Password","type" : "password","onkeypress":"myKeypress"}]}

卡洛斯。

于 2013-11-06T14:20:07.580 回答