Bootstrap實(shí)現(xiàn)省市區(qū)三級(jí)聯(lián)動(dòng)(親測(cè)可用)
bootstrap三級(jí)聯(lián)動(dòng)很常用,必備
本文實(shí)例就為大家分享了Bootstrap實(shí)現(xiàn)省市區(qū)三級(jí)聯(lián)動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
html頁(yè)面
<!-- 省市區(qū)三級(jí)聯(lián)動(dòng) begin --> <div class="form-group"> <label class="col-sm-2 control-label"><i>*</i>所在地址</label> <div class="col-sm-3"> <select name="input_province" id="input_province" class="form-control" > <option value="">--請(qǐng)選擇--</option> </select> </div> <div class="col-sm-3"> <select name="input_city" id="input_city" class="form-control"> <option value=""></option> </select> </div> <div class="col-sm-3"> <select name="input_area" id="input_area" class="form-control"> <option value=""></option> </select> </div> </div> <!-- 省市區(qū)三級(jí)聯(lián)動(dòng) end-->
js部分
<!-- 三級(jí)聯(lián)動(dòng) begin --> <script type="text/javascript" src="/js/plugins/address/address.js"></script> <script > $(function () { var html = ""; $("#input_city").append(html); $("#input_area").append(html); $.each(pdata,function(idx,item){ if (parseInt(item.level) == 0) { html += "<option value="+item.code+" >"+ item.names +"</option> "; } }); $("#input_province").append(html); $("#input_province").change(function(){ if ($(this).val() == "") return; $("#input_city option").remove(); $("#input_area option").remove(); //var code = $(this).find("option:selected").attr("exid"); var code = $(this).find("option:selected").val(); code = code.substring(0,2); var html = "<option value=''>--請(qǐng)選擇--</option>"; $("#input_area option").append(html); $.each(pdata,function(idx,item){ if (parseInt(item.level) == 1 && code == item.code.substring(0,2)) { html +="<option value="+item.code+" >"+ item.names +"</option> "; } }); $("#input_city ").append(html); }); $("#input_city").change(function(){ if ($(this).val() == "") return; $("#input_area option").remove(); var code = $(this).find("option:selected").val(); code = code.substring(0,4); var html = "<option value=''>--請(qǐng)選擇--</option>"; $.each(pdata,function(idx,item){ if (parseInt(item.level) == 2 && code == item.code.substring(0,4)) { html +="<option value="+item.code+" >"+ item.names +"</option> "; } }); $("#input_area ").append(html); }); }); </script> <!-- 三級(jí)聯(lián)動(dòng) end -->
我把js文件給上傳上來(lái)了,點(diǎn)擊這里
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript中關(guān)于執(zhí)行環(huán)境的雜談
如你所知,javascript里執(zhí)行環(huán)境是作為一個(gè)最核心的概念存在的。相信廣大FE筒子們對(duì)于這個(gè)概念不會(huì)陌生,它定義了變量或函數(shù)有權(quán)訪問(wèn)其他數(shù)據(jù)范圍以及其行為。2011-08-08Web網(wǎng)站都變成灰色有哪些方法可以快速實(shí)現(xiàn)(解決方案)
有些時(shí)候我們需要把網(wǎng)站頁(yè)面變成黑白色或灰色,特別是對(duì)于一些需要悼念的日子,以及一些影響力很大的偉人逝世或紀(jì)念日的時(shí)候,都會(huì)讓網(wǎng)站的全部網(wǎng)頁(yè)變成灰色(黑白色),以表示我們對(duì)逝者或者英雄的緬懷和悼念2022-12-12微信小程序使用picker組件出現(xiàn)的問(wèn)題探究
這篇文章主要介紹了微信小程序自定義可搜索的picker組件,主要包括自定義可搜索的picker組件的代碼以及調(diào)用實(shí)例,這里的搜索框使用的是vant微信小程序組件庫(kù),picker使用的微信小程序的原生組件,需要的朋友可以參考下2023-01-01JS點(diǎn)擊鏈接后慢慢展開(kāi)隱藏著圖片的方法
這篇文章主要介紹了JS點(diǎn)擊鏈接后慢慢展開(kāi)隱藏著圖片的方法,實(shí)例分析了javascript操作圖片的隱藏與現(xiàn)實(shí)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02