json数据的二级联动

来源:互联网 发布:网络推广任务 编辑:程序博客网 时间:2024/04/30 10:37
<script type="text/javascript">var jsondata={"elements":[{"key":"2005","value":["01","02","03","05","04"]},{"key":"2006","value":["01","02","03"]}]};var jsonobjct=eval(jsondata);var json=jsonobjct.elements;      function init() {  var option1 = '';  $.each(json, function(index, indexItems) {     option1 += "<option >"     + indexItems.key + "</option>";  });  $("#year").append(option1);  $("#year").bind("change", function() {   selectIssue(json);     }); } function selectIssue(data) {  var option2 = '';  var selectedIndex = $("#year :selected").text();  $("#issue").empty();  $.each(data, function(index, indexItems) {     if (indexItems.key != selectedIndex) {     return;  } else {                 $.each(indexItems.value, function(index, Items) {          option2 += "<option>"  + Items + "</option>";   });                          }  });  $("#issue").append(option2); };   function url(){    var year=  $("#year :selected").text();    var issue=  $("#issue :selected").text();   window.location.href=year+issue+"p/";   }</script></head><body onload="init()"><form>  <select id="year">    <option  selected="selected">年</option>  </select>  <select id="issue">  <option selected="selected">期号</option>  </select>   <input type="button" value="确定" onclick="url()"> </input></form></body>
<img src="http://img.blog.csdn.net/20160427165523656?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

0 0
原创粉丝点击