Home > php教程 > php手册 > 下拉菜单联动显示(读数据库)

下拉菜单联动显示(读数据库)

WBOY
Release: 2016-06-07 11:42:32
Original
1050 people have browsed it

点击最初的下拉菜单选择板块内容~然后读取数据库获取下级分类,然后jq输出分类的下级菜单~并且绑定同一个事件,修改后也许就可以应用到你们项目中;用jquery写的,第一次分享,觉得不好的请轻喷~~
js代码如下: $(".js_type").live('change',function(){<br>         var _this=$(this);<br>         var _this_id=_this.attr('id');<br>         var url='<!--{:U("Lib/ajaxType")}-->';<br>         var $v=_this.val();<br>         _this.nextAll("select").remove();<br>         switch(_this_id){<br>             case 'js_plateid':{<br>                 var data='plateid='+$v;<br>             } break;<br>             case 'js_pid': var data='uid='+$v; break;<br>         };<br>         $('<span>',{'class':'loadPtype'}).insertAfter(_this);<br>         $('.loadPtype').text("加载中...");<br>         $.ajax({<br>             'url':url,<br>             'type':'POST',<br>             'data':data,<br>             'success':function(data){<br>                 var obj=jQuery.parseJSON(data);<br>                 var option='';<br>                 if(obj!=null){<br>                     switch(_this_id){<br>                         case 'js_plateid':{<br>                             var $new_select=$('<select>',{'class':'js_type','id':'js_pid'});<br>                         };break;<br>                         case 'js_pid':{<br>                             var $new_select=$('<select>',{'name':'subtypeid'});    <br>                         };break;<br>                     }<br>                     $new_select.insertAfter(_this);<br>                     $('.loadPtype').remove();<br>                     for(var i=0;i<obj.length></obj.length>                         option+="<option>"+obj[i].typename+"</option>";<br>                     }<br>                     $new_select.html(option);<br>                 }else{<br>                     $(".loadPtype").text('无二级分类');<br>                 } <br>             }<br>         });<br>     });</select></select></span>html代码:

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template