<script type="text/javascript">
var flagflag = false
$(function(){
$.post("dropdownlist!selectAllProvinceCityTown.action",function(data){
var json=eval(data)
for(var i = 0,len = json.lengthi<leni++){
if($==json[i].id){
$('#cityid').empty()
$('#cityid').append("<option value=\"\">---请选择---</option>")
$('#townid').empty()
$('#townid').append("<option value=\"\">---请选择---</option>")
$('#provinceid').append($("<option value='"+json[i].id+"' selected='selected'>"+json[i].name+"</option>"))
querycitybyprovince()
}
else
{
$('#provinceid').append($("<option value='"+json[i].id+"'>"+json[i].name+"</option>"))
}
}
},"json")
$('#provinceid').change(function(){
$('#cityid').empty()
$('#cityid').append("<option value=\"\">---请选择---</option>")
$('#townid').empty()
$('#townid').append("<option value=\"\">---请选择---</option>")
querycitybyprovince()
})
})
function querycitybyprovince()
{
var provinceid = document.getElementById('provinceid').value
if(provinceid==1)
{
provinceid = -1
}
$.post("dropdownlist!selectAllProvinceCityTown.action",,function(data){
var json=eval(data)
for(var i = 0,len = json.lengthi<leni++){
if($==json[i].id){
$('#townid').empty()
$('#townid').append("<option value=\"\">---请选择---</option>")
$('#cityid').append($("<option value='"+json[i].id+"' selected='selected'>"+json[i].name+"</option>"))
querytownbycity()
}
else{
$('#cityid').append($("<option value='"+json[i].id+"'>"+json[i].name+"</option>"))
}
}
$('#cityid').change(function(){
//clearOptions(document.getElementById('townid'))
//$('#townid').empty()
$('#townid').empty()
$('#townid').append("<option value=\"\">---请选择---</option>")
querytownbycity()
},"json")
})
}
function querytownbycity()
{
var cityid = document.getElementById('cityid').value
$.post("dropdownlist!selectAllProvinceCityTown.action",,function(data){
var json=eval(data)
$('#townid').empty()
$('#townid').append("<option value=\"\">---请选择---</option>")
for(var i = 0,len = json.lengthi<leni++){
if($==json[i].id){
$('#townid').append($("<option value='"+json[i].id+"' selected='selected'>"+json[i].name+"</option>"))
}
else{
$('#townid').append($("<option value='"+json[i].id+"'>"+json[i].name+"</option>"))
}
}
},"json")
}
页面端:
<select name="provinceid" class="bk_01" id="provinceid"
style="WIDTH: 120px">
<option value="1">
---请选择---
</option>
</select>
<select name="cityid" class="bk_01" id="cityid"
style="WIDTH: 120px">
<option value="">
---请选择---
</option>
</select>
<select name="townid" class="bk_01" id="townid"
style="WIDTH: 120px">
<option value="">
---请选择---
</option>
</select>
希望对你有帮助,希望及时采纳,谢谢!
<HTML><HEAD>
<TITLE>选择下拉菜单-www.51windows.Net</TITLE>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
<META NAME="Description" CONTENT="Power by 51windows.Net">
</HEAD>
<BODY>
<p>选定一项或多项然后点击添加或移除(按住shift或ctrl可以多选),或在选择项上双击进行添加和移除。</p>
<form method="post" name="myform">
<table border="0" width="300">
<tr>
<td width="40%">
<select style="width:100%" multiple name="list1" size="12" ondblclick="moveOption(document.myform.list1, document.myform.list2)">
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="山东">山东</option>
<option value="安徽">安徽</option>
<option value="重庆">重庆</option>
<option value="福建">福建</option>
<option value="甘肃">甘肃</option>
<option value="广东">广东</option>
<option value="广西">广西</option>
<option value="贵州">贵州</option>
<option value="海南">海南</option>
<option value="河北">河北</option>
<option value="黑龙江">黑龙江</option>
<option value="河南">河南</option>
<option value="湖北">湖北</option>
<option value="湖南">湖南</option>
<option value="内蒙古">内蒙古</option>
<option value="江苏">江苏</option>
<option value="江西">江西</option>
<option value="吉林">吉林</option>
<option value="辽宁">辽宁</option>
<option value="宁夏">宁夏</option>
<option value="青海">青海</option>
<option value="山西">山西</option>
<option value="陕西">陕西</option>
<option value="四川">四川</option>
<option value="天津">天津</option>
<option value="西藏">西藏</option>
<option value="新疆">新疆</option>
<option value="云南">云南</option>
<option value="浙江">浙江</option>
<option value="香港">香港</option>
<option value="澳门">澳门</option>
<option value="台湾">台湾</option>
<option value="其他">其他</option>
</select>
</td>
<td width="20%" align="center">
<input type="button" value="添加" onclick="moveOption(document.myform.list1, document.myform.list2)"><br><br>
<input type="button" value="全选" onclick="moveAllOption(document.myform.list1, document.myform.list2)"><br><br>
<input type="button" value="删除" onclick="moveOption(document.myform.list2, document.myform.list1)"><br><br>
<input type="button" value="全删" onclick="moveAllOption(document.myform.list2, document.myform.list1)">
</td>
<td width="40%">
<select style="width:100%" multiple name="list2" size="12" ondblclick="moveOption(document.myform.list2, document.myform.list1)">
</select>
</td>
</tr>
</table>
值:<input type="text" name="city" size="40" value="" />
</form>
<script language="JavaScript">
<!--
function moveOption(e1, e2){
try{
for(var i = 0i <e1.options.lengthi++){
if(e1.options[i].selected){
var e = e1.options[i]
e2.options.add(new Option(e.text, e.value))
e1.remove(i)
i = i - 1
}
}
document.myform.city.value=getvalue(document.myform.list2)
}
catch(e){}
}
function getvalue(geto){
var allvalue = ""
for(var i = 0i <geto.options.lengthi++){
allvalue += geto.options[i].value + ","
}
return allvalue
}
function moveAllOption(e1, e2){
try{
for(var i = 0i <e1.options.lengthi++){
var e = e1.options[i]
e2.options.add(new Option(e.text, e.value))
e1.remove(i)
i = i - 1
}
document.myform.city.value=getvalue(document.myform.list2)
}
catch(e){
}
}
//-->
</script>
</BODY>
</HTML>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)