基于jquery的二級(jí)聯(lián)動(dòng)菜單實(shí)現(xiàn)代碼
<!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=gb2312" />
<title>jQuery 二級(jí)聯(lián)動(dòng)</title>
<script src="http://img.jb51.net/jslib/jquery/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#province").change(function(){
$("#province option").each(function(i,o){
if($(this).attr("selected"))
{
$(".city").hide();
$(".city").eq(i).show();
}
});
});
$("#province").change();
});
</script>
</head>
<body>
<select id="province">
<option>----請(qǐng)選擇省份----
<option>北京
<option>上海
<option>江蘇
</select>
<select class="city">
<option>----請(qǐng)選擇城市----
</select>
<select class="city">
<option>東城</option>
<option>西城</option>
<option>崇文</option>
<option>宣武</option>
<option>朝陽(yáng)</option>
</select>
<select class="city">
<option>黃浦</option>
<option>盧灣</option>
<option>徐匯</option>
<option>長(zhǎng)寧</option>
<option>靜安</option>
</select>
<select class="city">
<option>南京</option>
<option>鎮(zhèn)江</option>
<option>蘇州</option>
<option>南通</option>
<option>揚(yáng)州</option>
</select>
</body>
</html>
JQuery實(shí)現(xiàn)的二級(jí)聯(lián)動(dòng)菜單
先看頁(yè)面代碼
Html代碼
<tr>
<td align="right" width="30%"><span class="red">*</span>短信類型:</td>
<td align="left">
<select name='city' id='first'>
<option value='-1'>==請(qǐng)選擇類型==</option>
<#list typeList as t>
<option value='${t.id}'>${t.name}</option>
</#list>
</select>
<span id="second">
<select id="area" name="msgTypeId">
</select>
</span>
</td>
</tr>
其中id為first的下拉列表為第一個(gè)下拉列表,id為second的區(qū)域?yàn)榈诙€(gè)下拉列表。
JavaScript代碼:
<script language="javascript">
$(function(){
$("#second").hide(); //初始化的時(shí)候第二個(gè)下拉列表隱藏
$("#first").change(function(){ //當(dāng)?shù)谝粋€(gè)下拉列表變動(dòng)內(nèi)容時(shí)第二個(gè)下拉列表將會(huì)顯示
var parentId=$("#first").val();
if(null!= parentId && ""!=parentId){
$.getJSON("http://localhost/msg/getSecondTypesJson",{id:parentId},function(myJSON){
var options="";
if(myJSON.length>0){
options+="<option value=''>==請(qǐng)選擇類型==</option>";
for(var i=0;i<myJSON.length;i++){
options+="<option value="+myJSON[i].id+">"+myJSON[i].name+"</option>";
}
$("#area").html(options);
$("#second").show();
}
else if(myJSON.length<=0){
$("#second").hide();
}
});
}
else{
$("#second").hide();
}
});
});
</script>
- 用jquery實(shí)現(xiàn)下拉菜單效果的代碼
- 用jquery實(shí)現(xiàn)的一個(gè)超級(jí)簡(jiǎn)單的下拉菜單
- Jquery帶搜索框的下拉菜單
- jquery實(shí)現(xiàn)鼠標(biāo)滑過(guò)顯示二級(jí)下拉菜單效果
- jQuery點(diǎn)擊彈出下拉菜單的小例子
- jquery實(shí)現(xiàn)可點(diǎn)擊伸縮與展開(kāi)的菜單效果代碼
- 用jquery寫(xiě)的菜單從左往右滑動(dòng)出現(xiàn)
- 基于JQuery的簡(jiǎn)單實(shí)現(xiàn)折疊菜單代碼
- jquery實(shí)現(xiàn)左右滑動(dòng)菜單效果代碼
- jquery插件實(shí)現(xiàn)堆疊式菜單
相關(guān)文章
Jquery修改頁(yè)面標(biāo)題title其它JS失效的解決方法
這篇文章主要介紹了Jquery修改頁(yè)面標(biāo)題title其它JS失效的解決方法,很簡(jiǎn)單,很實(shí)用,需要的朋友可以參考下2014-10-10詳解jquery插件jquery.viewport.js學(xué)習(xí)使用方法
本篇文章主要介紹了詳解jquery插件jquery.viewport.js學(xué)習(xí)使用方法,具有一定的參考價(jià)值,有興趣的可以了解一下2017-09-09jQuery插件datalist實(shí)現(xiàn)很好看的input下拉列表
本文給大家分享的是使用jQuery實(shí)現(xiàn)的房HTML5中的一個(gè)好看的input框很好看的下拉列表--datalist,兼容性非常不錯(cuò),這里推薦給大家,有需要的小伙伴可以參考下。2015-07-07jquery實(shí)現(xiàn)左右無(wú)縫輪播圖
這篇文章主要為大家詳細(xì)介紹了基于jquery實(shí)現(xiàn)左右無(wú)縫輪播圖的具體代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05jQuery表單校驗(yàn)插件validator使用方法詳解
這篇文章主要為大家詳細(xì)介紹了jQuery表單校驗(yàn)插件validator的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02DataTables+BootStrap組合使用Ajax來(lái)獲取數(shù)據(jù)并且動(dòng)態(tài)加載dom的方法(排序,過(guò)濾,分頁(yè)等)
Datatables是一款jquery表格插件。它是一個(gè)高度靈活的工具,可以將任何HTML表格添加高級(jí)的交互功能。這篇文章主要介紹了DataTables+BootStrap組合使用Ajax來(lái)獲取數(shù)據(jù)并且動(dòng)態(tài)加載dom的方法(排序,過(guò)濾,分頁(yè)等),需要的朋友可以參考下2016-11-11JQuery Tips(3) 關(guān)于$()包裝集內(nèi)元素的改變
JQuery包裝集內(nèi)的元素在一開(kāi)始的選定后,還可以通過(guò)一系列JQuery提供的方法對(duì)包裝集內(nèi)的元素進(jìn)行擴(kuò)充,修改,篩選,刪除find()方法 VS filter()方法2009-12-12