Bootstrap實(shí)現(xiàn)省市區(qū)三級聯(lián)動(親測可用)
bootstrap三級聯(lián)動很常用,必備
本文實(shí)例就為大家分享了Bootstrap實(shí)現(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文件給上傳上來了,點(diǎn)擊這里
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Js動態(tài)設(shè)置rem來實(shí)現(xiàn)移動端字體的自適應(yīng)代碼
這篇文章主要介紹了Js動態(tài)設(shè)置rem來實(shí)現(xiàn)移動端字體的自適應(yīng)代碼,代碼簡單易懂非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-10-10
探究Javascript模板引擎mustache.js使用方法
這篇文章主要為大家介紹了Javascript模板引擎mustache.js使用方法,mustache.js是一個簡單強(qiáng)大的Javascript模板引擎,使用它可以簡化在js代碼中的html編寫,壓縮后只有9KB,非常值得在項(xiàng)目中使用,感興趣的小伙伴們可以參考一下2016-01-01
一文詳解如何使npm-scripts更好維護(hù)的配置方法
這篇文章主要為大家介紹了如何使npm-scripts更好維護(hù)的配置方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
JS實(shí)現(xiàn)仿雅虎首頁快捷登錄入口及導(dǎo)航模塊效果
這篇文章主要介紹了JS實(shí)現(xiàn)仿雅虎首頁快捷登錄入口及導(dǎo)航模塊效果,涉及JavaScript響應(yīng)鼠標(biāo)事件遍歷頁面元素的實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09
Javascript中prototype屬性實(shí)現(xiàn)給內(nèi)置對象添加新的方法
這篇文章主要介紹了Javascript中prototype屬性實(shí)現(xiàn)給內(nèi)置對象添加新的方法,涉及javascript中prototype屬性的使用技巧,需要的朋友可以參考下2015-05-05
JavaScript中call,apply,bind的區(qū)別與實(shí)現(xiàn)
這篇文章主要介紹了JavaScript中call,apply,bind的區(qū)別與實(shí)現(xiàn),文章通過圍繞主題思想展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09
淺談Javascript如何實(shí)現(xiàn)勻速運(yùn)動
這篇文章主要介紹了淺談Javascript如何實(shí)現(xiàn)勻速運(yùn)動的方法及相關(guān)代碼,需要的朋友可以參考下2014-12-12

