Bootstrap實現(xiàn)省市區(qū)三級聯(lián)動(親測可用)
更新時間:2019年07月26日 15:15:35 作者:是金子早晚要花光
這篇文章主要為大家詳細介紹了Bootstrap實現(xiàn)省市區(qū)三級聯(lián)動,具有一定的參考價值,感興趣的小伙伴們可以參考一下
bootstrap三級聯(lián)動很常用,必備
本文實例就為大家分享了Bootstrap實現(xiàn)省市區(qū)三級聯(lián)動的具體代碼,供大家參考,具體內(nèi)容如下
html頁面
<!-- 省市區(qū)三級聯(lián)動 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="">--請選擇--</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ū)三級聯(lián)動 end-->
js部分
<!-- 三級聯(lián)動 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=''>--請選擇--</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=''>--請選擇--</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>
<!-- 三級聯(lián)動 end -->
我把js文件給上傳上來了,點擊這里
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
javascript中關(guān)于執(zhí)行環(huán)境的雜談
如你所知,javascript里執(zhí)行環(huán)境是作為一個最核心的概念存在的。相信廣大FE筒子們對于這個概念不會陌生,它定義了變量或函數(shù)有權(quán)訪問其他數(shù)據(jù)范圍以及其行為。2011-08-08
Web網(wǎng)站都變成灰色有哪些方法可以快速實現(xiàn)(解決方案)
有些時候我們需要把網(wǎng)站頁面變成黑白色或灰色,特別是對于一些需要悼念的日子,以及一些影響力很大的偉人逝世或紀(jì)念日的時候,都會讓網(wǎng)站的全部網(wǎng)頁變成灰色(黑白色),以表示我們對逝者或者英雄的緬懷和悼念2022-12-12

