jQuery how to load some json records into a form fields?

后端 未结 4 1948
心在旅途
心在旅途 2020-12-09 00:29

i have a json file:

 {
    \"data\": \"Click\",
    \"size\": \"Here\"    }

and a form:

First name:
4条回答
  •  死守一世寂寞
    2020-12-09 01:03

    Could you take a look at the JQuery loadJSON plugin on the http://code.google.com/p/jquery-load-json/ ? On the page http://code.google.com/p/jquery-load-json/wiki/WorkingWithFormElements is explained how this plugin load JSON object into the form. You can also find one live example here http://jquery-load-json.googlecode.com/svn/trunk/edit.html?ID=17. I think that this is exactly what you need. Just create empty form and load json in the form using the following code:

    $('form').loadJSON(data);
    

    This plugin handles all form elements such as check boxes, select list radio buttons etc. If you use it you will need to download plugin from the http://code.google.com/p/jquery-load-json/source/browse/trunk/scripts/jquery.loadJSON.js.

提交回复
热议问题