你的位置:首页 > Java教程

[Java教程]如何根据Jquery实现两级联动


<script language="javascript" type="text/javascript" >
$(function (){
      $.ajax({
            url:<select:link page="/tobaccoinfo.do?method=getBrandList" />,
            type: "get" ,
            dataType: "json" ,
            success: function (result){
                   var str="<option value=''>全部</option>" ;
                   for (var i=0;i<result.length;i++){
                        str+= "<option value="+result[i].id+">"+result[i].name+ "</option>" ;
                  }
                  $( "#brandid" ).html(str);
            }
      });
      $( "#brandid" ).change( function(){
             var brandid=$("#brandid" ).val();
            $.ajax({
                  url:<select:link page="/tobaccoinfo.do?method=getTobaccoName" />,
                  type: 'get' ,
                  data:{
                         'brandid' :brandid
                  },
                  dataType: 'json' ,
                  success: function (result){
                         var str="<option value=''>全部</option>" ;
                         for (var i=0;i<result.length;i++){
                              str+= "<option value="+result[i].id_+ ">"+result[i].name_+ "</option>" ;
                        }
                        $( "#tobaccoId" ).empty().html(str);
                  }
            });
      });
});
</script>

<body>卷烟品牌:<select:select property="brandid" addspacerow="false" ></select:select>
卷烟名称:<select:select property="tobaccoId" addspacerow="false" ></select:select></body>