如何编写函数来填充表单的控件... [英] How Can I Write A Function To Fill The Controles Of A Form ...

查看:60
本文介绍了如何编写函数来填充表单的控件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:

i在我的项目中有很多表单,我希望在我的代码中有一个deserilizeForm和serializeForm函数,我不允许使用插件。

i需要这个函数:

my question is :
i have lots of form in my project , and i want to have a "deserilizeForm" and "serializeForm" functions in my code , i'm not allowed to use a Plugin .
i need the function to be like this :

deserilizeForm: function (DIVID, obj) {//fill
          debugger


       for (var i in obj) {
           var id = i;
           var val = obj[i];
           var control = $('#' + DIVID + ' #' + id + ' [name="' + id + '"');


           switch (contol.type) {
               case 'text':
                   control.val(val);
                   // code
                   break;

               default:
                   // code
           }
       }
        },



obj是一个Json obj,例如:


the obj is a Json obj for example :

{ "index": 1,
                        "firstName": "John",
                        "lastName": "Jones",
                        "joined": "April 2015",
                        "Country": "Amman",
                        "Gender": "Male",
                        "Active": "False",
                        "NOC": 4
                       
                    }

推荐答案

' #' + DIVID + ' #' + id + ' [name =' + id + < span class =code-string>' ');


switch (contol.type){
case ' text'
control.val(val);
// 代码
break ;

默认
// 代码
}
}
},
('#' + DIVID + ' #' + id + ' [name="' + id + '"'); switch (contol.type) { case 'text': control.val(val); // code break; default: // code } } },



obj是一个Json obj,例如:


the obj is a Json obj for example :

{ "index": 1,
                        "firstName": "John",
                        "lastName": "Jones",
                        "joined": "April 2015",
                        "Country": "Amman",
                        "Gender": "Male",
                        "Active": "False",
                        "NOC": 4
                       
                    }


这篇关于如何编写函数来填充表单的控件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆