将json数据写入对应的table中。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="jquery-2.0.0.js"></script> <script type="text/javascript"> function json_value(){ var value_1 = '{"spectrum":[{"spec_freq":111,"spec_type":2, "spec_lo":132}, {"spec_freq":151,"spec_type":2, "spec_lo":129}],"take":"12fdsafds"}'; var value_2 = eval("("+value_1+")"); //console.log(value_2.spectrum[1].spec_lo); //alert((value_2.spectrum[1].spec_lo)); console.log(value_2.spectrum.length); //读取数组长度 return value_2.spectrum; } function test() { var spec = ["spec_freq", "spec_type", "spec_lo"]; var spectrum_tol = json_value(); spectrum_tol[1][spec[0]] = 250; for (index_tol in spectrum_tol) { for (index_spec in spec) { if (spec[index_spec] != "spec_type") { $('[name="'+spec[index_spec]+'"]').eq(index_tol).text(spectrum_tol[index_tol][spec[index_spec]]); } else { $('[name="'+spec[index_spec]+'"]').eq(index_tol).val(spectrum_tol[index_tol][spec[index_spec]]); } } } } </script> </head> <body onload="json_value();"> <table border="1" width="90%" align="center"> <tr align="center"> <td name="spec_freq">1</td> <td width="20%"> <select name="spec_type" style="100%" dir="ltr"> <option value="1">1</option> <option value="2">2</option> </select> </td> <td name="spec_lo">1</td> </tr> <tr align="center"> <td name="spec_freq">2</td> <td> <select name="spec_type" > <option value="1">1</option> <option value="2">2</option> </select> </td> <td name="spec_lo">2</td> </tr> </table> <table width="90%" align="center"> <tr> <td align="right"> <input type="button" style="200px" name="test" value="test" onclick="test();"> </td> </tr> </table> </body> </html>