我正在使用 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 文件或代码中添加其他内容?
任何帮助深表感谢。
谢谢,卡洛斯