dekey,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<input name="form.pj" value="1235">
<input name="form.cr" value="123">
<input name="form.app.id" value="1234">
<input name="form.app.fm.id" value="12356">
<script>
var inp = document.querySelectorAll("input"), form = {};
for (var i=0; i<inp.length; i++) {
var arr = inp[i].name.split('.'), tmp = form;
for (var k=1; k<arr.length-1; k++) { !tmp[arr[k]] && (tmp[arr[k]] = {}) ; tmp = tmp[arr[k]]}
tmp[arr[k]] = inp[i].value
}
alert(JSON.stringify(form));
</script>
</body>
</html>
|