分享 把表单元素读取成 JSON 的一个小插件

zfben · July 02, 2012 · 2461 hits
$('<div><input name="a" value="a" /></div>').to_json()
  //=> {a: 'a'}
$('<div><input name="a.b" value="b" /></div>').to_json()
  //=> {a: {b: 'b'}}
$('<div><input name="a.b[]" value="1" /><input name="a.b[]" value="2" /></div>').to_json()
  //=> {a: {b: ['1', '2']}}

插件下载地址:https://raw.github.com/benz303/jQuery.fn.to_json/gh-pages/jQuery.fn.to_json.js

Github 地址:http://benz303.github.com/jQuery.fn.to_json/

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.