jQuery 下拉選單選擇 載入 (練手例項)
<html>
<head>
<title>Next join Test</title>
<style type="text/css">
.font-color{
width:150px;
height: 200px;
color: rgb(79,129,189)
}
#div1{border:1px solid #000; width: 50%; position:relative; top: 20%; background-color: #ccc;}
#province{position:relative; top: -170px; left: 10px;}
#div2{border:1px solid #000; width: 50%; position:relative; top: 19%; background-color: #ccc;}
</style>
<script type="text/javascript" src="lib/jquery-1.4.2.js"></script>
<script type="text/javascript">
var simpleNodes =[
{ id:1, pId:0, name:"手機", ename:"Mobile", open:true},
{ id:11, pId:1, name:"諾基亞", ename:"Nokia"},
{ id:111, pId:11, name:"C6(音樂版)", ename:"C6(Music)"},
{ id:112, pId:11, name:"X6(導航版)", ename:"X6(GPS)"},
{ id:113, pId:11, name:"5230(世博版)", ename:"5230(SB)"},
{ id:114, pId:11, name:"N97mini", ename:"N97mini"},
{ id:12, pId:1, name:"三星", ename:"Samsung"},
{ id:121, pId:12, name:"I9000(聯通版)", ename:"I9000(Unicom)"},
{ id:122, pId:12, name:"I9000(移動版)", ename:"I9000(China Mobile)"},
{ id:123, pId:12, name:"Galaxy Naos", ename:"Galaxy Naos"},
{ id:124, pId:12, name:"Fascinate", ename:"Fascinate"},
{ id:13, pId:1, name:"索愛", ename:"Sony Ericsson"},
{ id:131, pId:13, name:"U1i(Satio)", ename:"U1i(Satio)"},
{ id:132, pId:13, name:"U5i(Vivaz)", ename:"U5i(Vivaz)"},
{ id:133, pId:13, name:"X10i", ename:"X10i"},
{ id:134, pId:13, name:"Aino mini", ename:"Aino mini"}];
//初始化載入province
function province(){
for(i=0; i < simpleNodes.length; i++ ){
if(simpleNodes[i].pId == "1"){
var newoption = document.createElement("option");
newoption.text = simpleNodes[i].name;
newoption.value = simpleNodes[i].id;
form1.province.options.add(newoption);
}
}
}
$(function(){
$("#province").change(function(){
var value = this.value;
var len = form1.city.length;
if(len > 0){
$("#city option").remove();
}
for(i=0; i < simpleNodes.length; i++ ){
if(simpleNodes[i].pId == value){
//效率過低
//$("#city").append("<option value="+simpleNodes[i].id+">"+simpleNodes[i].name+"</option>");
//$('<option/>',{
// value:simpleNodes[i].id,
// text:simpleNodes[i].name}).appendTo("#city");
//JS
var newoption = document.createElement("option");
newoption.text = simpleNodes[i].name;
newoption.value = simpleNodes[i].id;
form1.city.options.add(newoption);
}
}
});
$("#city").dblclick(function(){
var value = $("#city option:selected").val();
var text = $("#city option:selected").text();
var flag = false;
var len = $("#selcity option").length;
//alert(len);
if(len > 0){
$("#selcity option").each(function(i){
if(value == $(this).val()){
flag = true;
alert("已選擇,請勿重選!");
return false;
}
});
if(!flag){
//不刪除原節點
//$("#selcity").append("<option value="+ value +">"+ text +"</option>");
$("#city option:selected").appendTo("#selcity");
}
}else{
//不刪除原節點
//$("#city option:selected").append("<option value="+ value +">"+ text +"</option>");
$("#city option:selected").appendTo("#selcity");
}
});
$("#selcity").dblclick(function(){
$("#selcity option:selected").remove();
//還原
//$("#selcity option:selected").appendTo("#city");
});
});
</script>
</head>
<body onload="javascript:province();">
<center>
<div id="div2">
<span><font color="blue"><strong>jQuery + JS 下拉框載入選擇</strong></font></span>
</div>
<div id="div1">
<form id="form1" name="form1">
<select id="province" name="province">
<option value="N" selected="selected">請選擇</option>
</select>
<select size="10" class="font-color" id="city" name="city" style="width:150px"></select>
<select multiple="multiple" class="font-color" id="selcity" name="selcity"></select>
</form>
<div>
</center>
</body>
</html>
相關文章
- jQuery美化select下拉選單程式碼例項jQuery
- jQuery操作select下拉選單程式碼例項jQuery
- jQuery 動態載入下拉框選項(Django)jQueryDjango
- 選擇下拉選單項實現跳轉效果
- jQuery 二級下拉選單jQuery
- css二級下拉選單程式碼例項CSS
- select下拉選單美化程式碼例項
- jQuery結合ul和li實現的下拉選單例項程式碼jQuery單例
- 禁用文字選擇、右鍵選單例項程式碼單例
- jQuery 美化select下拉選單jQuery
- 滑鼠懸浮出現下拉選單程式碼例項
- css水平下拉導航選單程式碼例項CSS
- 模擬select下拉選單程式碼例項
- jquery select下拉選單新增或者刪除option項jQuery
- jQuery刪除select下拉選單中所有option項jQuery
- jQuery結合PHP+MySQL實現二級聯動下拉選單[例項]jQueryPHPMySql
- select下拉選單項互換效果程式碼例項
- javascript刪除select下拉選單項程式碼例項JavaScript
- jquery如何獲取select下拉選單選中項的值和文字jQuery
- 選中select下拉選單項提交表單
- jQuery 省市級聯選單程式碼例項jQuery
- excel下拉選擇項怎麼設定 excel怎麼新增下拉選項內容Excel
- jq+css+html打造下拉導航選單例項CSSHTML單例
- 原生javascript操作select下拉選單程式碼例項JavaScript
- select下拉選單級聯效果例項程式碼
- select級聯下拉選單程式碼例項分析
- css三級下拉導航選單程式碼例項CSS
- 模擬美化select下拉選單程式碼例項
- jQuery與CSS二級下拉選單jQueryCSS
- jquery如何操作select下拉選單jQuery
- 選擇select下拉選單網頁跳轉網頁
- jquery新增或者刪除select下拉選單項程式碼jQuery
- 點選文字框彈出可檢索下拉選單程式碼例項
- Js/JQuery下拉框新增新選項JSjQuery
- jQuery選項卡例項程式碼jQuery
- jQuery選擇器——表單元素過濾選擇器jQuery
- 刪除和新增select下拉選單option項程式碼例項
- 模擬實現select下拉選單例項程式碼單例