jQuery select表單提交省市區(qū)城市三級聯(lián)動核心代碼
更新時間:2014年06月09日 10:12:05 作者:
這篇文章主要介紹了jQuery select表單提交省市區(qū)城市三級聯(lián)動核心代碼,需要的朋友可以參考下
jQuery select表單提交省市區(qū)城市三級聯(lián)動,引用的是“jquery-1.7.min”類庫,地區(qū)碼查詢地區(qū)名用數(shù)組存在AreaData_min,下面摘要部分代碼:
SelectArea.htm文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery select表單提交省市區(qū)城市三級聯(lián)動</title>
<script src="jquery-1.7.min.js" type="text/javascript"></script>
<script src="Area.js" type="text/javascript"></script>
<script src="AreaData_min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function (){
initComplexArea('seachprov', 'seachcity', 'seachdistrict', area_array, sub_array, '44', '0', '0');
});
//得到地區(qū)碼
function getAreaID(){
var area = 0;
if($("#seachdistrict").val() != "0"){
area = $("#seachdistrict").val();
}else if ($("#seachcity").val() != "0"){
area = $("#seachcity").val();
}else{
area = $("#seachprov").val();
}
return area;
}
function showAreaID() {
//地區(qū)碼
var areaID = getAreaID();
//地區(qū)名
var areaName = getAreaNamebyID(areaID) ;
alert("您選擇的地區(qū)碼:" + areaID + " 地區(qū)名:" + areaName);
}
//根據(jù)地區(qū)碼查詢地區(qū)名
function getAreaNamebyID(areaID){
var areaName = "";
if(areaID.length == 2){
areaName = area_array[areaID];
}else if(areaID.length == 4){
var index1 = areaID.substring(0, 2);
areaName = area_array[index1] + " " + sub_array[index1][areaID];
}else if(areaID.length == 6){
var index1 = areaID.substring(0, 2);
var index2 = areaID.substring(0, 4);
areaName = area_array[index1] + " " + sub_array[index1][index2] + " " + sub_arr[index2][areaID];
}
return areaName;
}
</script>
</head>
<body>
<label>請選擇省市地區(qū):</label></br>
<select id="seachprov" name="seachprov" onChange="changeComplexProvince(this.value, sub_array, 'seachcity', 'seachdistrict');"></select>
<select id="seachcity" name="homecity" onChange="changeCity(this.value,'seachdistrict','seachdistrict');"></select>
<span id="seachdistrict_div"><select id="seachdistrict" name="seachdistrict"></select></span>
<input type="button" value="獲取地區(qū)" onClick="showAreaID()"/>
</body>
</html>
程序下載地址:
jquery select表單提交省市區(qū)城市三級聯(lián)動
效果圖:
SelectArea.htm文件
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery select表單提交省市區(qū)城市三級聯(lián)動</title>
<script src="jquery-1.7.min.js" type="text/javascript"></script>
<script src="Area.js" type="text/javascript"></script>
<script src="AreaData_min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function (){
initComplexArea('seachprov', 'seachcity', 'seachdistrict', area_array, sub_array, '44', '0', '0');
});
//得到地區(qū)碼
function getAreaID(){
var area = 0;
if($("#seachdistrict").val() != "0"){
area = $("#seachdistrict").val();
}else if ($("#seachcity").val() != "0"){
area = $("#seachcity").val();
}else{
area = $("#seachprov").val();
}
return area;
}
function showAreaID() {
//地區(qū)碼
var areaID = getAreaID();
//地區(qū)名
var areaName = getAreaNamebyID(areaID) ;
alert("您選擇的地區(qū)碼:" + areaID + " 地區(qū)名:" + areaName);
}
//根據(jù)地區(qū)碼查詢地區(qū)名
function getAreaNamebyID(areaID){
var areaName = "";
if(areaID.length == 2){
areaName = area_array[areaID];
}else if(areaID.length == 4){
var index1 = areaID.substring(0, 2);
areaName = area_array[index1] + " " + sub_array[index1][areaID];
}else if(areaID.length == 6){
var index1 = areaID.substring(0, 2);
var index2 = areaID.substring(0, 4);
areaName = area_array[index1] + " " + sub_array[index1][index2] + " " + sub_arr[index2][areaID];
}
return areaName;
}
</script>
</head>
<body>
<label>請選擇省市地區(qū):</label></br>
<select id="seachprov" name="seachprov" onChange="changeComplexProvince(this.value, sub_array, 'seachcity', 'seachdistrict');"></select>
<select id="seachcity" name="homecity" onChange="changeCity(this.value,'seachdistrict','seachdistrict');"></select>
<span id="seachdistrict_div"><select id="seachdistrict" name="seachdistrict"></select></span>
<input type="button" value="獲取地區(qū)" onClick="showAreaID()"/>
</body>
</html>
程序下載地址:
jquery select表單提交省市區(qū)城市三級聯(lián)動
效果圖:

您可能感興趣的文章:
- 簡單實用jquery版三級聯(lián)動select示例
- jquery+json 通用三級聯(lián)動下拉列表
- 省市區(qū)三級聯(lián)動jquery實現(xiàn)代碼
- jQuery實現(xiàn)的省市縣三級聯(lián)動菜單效果完整實例
- jQuery+jsp實現(xiàn)省市縣三級聯(lián)動效果(附源碼)
- asp.net省市三級聯(lián)動的DropDownList+Ajax的三種框架(aspnet/Jquery/ExtJs)示例
- 基于jQuery+JSON的省市二三級聯(lián)動效果
- JSON+Jquery省市區(qū)三級聯(lián)動
- jquery實現(xiàn)的省市區(qū)三級聯(lián)動
- jQuery實現(xiàn)簡單三級聯(lián)動效果
相關文章
jQuery實現(xiàn)的下雪動畫效果示例【附源碼下載】
這篇文章主要介紹了jQuery實現(xiàn)的下雪動畫效果,涉及jQuery插件結合setInterval、animate進行動畫操作的相關使用技巧,并附帶源碼供讀者下載參考,需要的朋友可以參考下2018-02-02