情况是这样:doubleselect 里第一级是城市,第二级是对应的区域,城市和区域的对应关系保存cityMap里,一个城市有多个区域,选中城市自然会对应到该城市的区域, 现在 有一个checkbox ,后面有已有的城市和区域,比如: 北京 丰台区 ,当我选中的时候,要在doubleselect 的2级里面分别
显示出 北京 和丰台区 ,相关代码如下,因为 doubleselect 第一级城市里面有值,所以可以直接选中 和我传过去相等的城市,但第二级里没值的,怎么也让他显示出丰台区来,给出代码,谢谢大家了!!很急,不弄完过不了五一了,祝大家五一快乐!!function chooseFrp(id) {
var thisId = 'frp' + id;
//取消勾选则直接返回
if(document.getElementById(thisId).checked == false) {
return false;
}
var frpArray = document.getElementsByName("frpCheck");
for(var i = 0;i < frpArray.length;i++) {
if(id != i) {
var tempId = 'frp' + i;
document.getElementById(tempId).checked = false;
}
}
//读取地址信息到相应控件
$('dlyTypeVOfrpVOcity').value = $('frpCity' + id).value; //城市
$('dlyTypeVOfrpVOarea').value = $('frpDistrict' + id).value; //区域
}<%-- 这里是一个checkbox,后面是城市和区域,比如:北京 丰台区 ,选中后执行上面JS--%>
<input type="checkbox" name="frpCheck"
onclick='chooseFrp(<s:property value="#frpIndex.getIndex()"/>)'
value=""
id="frp<s:property value='#frpIndex.getIndex()'/>" />城市和区域
<s:doubleselect name="dlyTypeVO.frpVO.city"
id="dlyTypeVOfrpVOcity" list="cityMap.keySet()"
doubleName="dlyTypeVO.frpVO.area"
doubleId="dlyTypeVOfrpVOarea"
doubleList="cityMap[top]" headerKey=""
headerValue="请选择" />
显示出 北京 和丰台区 ,相关代码如下,因为 doubleselect 第一级城市里面有值,所以可以直接选中 和我传过去相等的城市,但第二级里没值的,怎么也让他显示出丰台区来,给出代码,谢谢大家了!!很急,不弄完过不了五一了,祝大家五一快乐!!function chooseFrp(id) {
var thisId = 'frp' + id;
//取消勾选则直接返回
if(document.getElementById(thisId).checked == false) {
return false;
}
var frpArray = document.getElementsByName("frpCheck");
for(var i = 0;i < frpArray.length;i++) {
if(id != i) {
var tempId = 'frp' + i;
document.getElementById(tempId).checked = false;
}
}
//读取地址信息到相应控件
$('dlyTypeVOfrpVOcity').value = $('frpCity' + id).value; //城市
$('dlyTypeVOfrpVOarea').value = $('frpDistrict' + id).value; //区域
}<%-- 这里是一个checkbox,后面是城市和区域,比如:北京 丰台区 ,选中后执行上面JS--%>
<input type="checkbox" name="frpCheck"
onclick='chooseFrp(<s:property value="#frpIndex.getIndex()"/>)'
value=""
id="frp<s:property value='#frpIndex.getIndex()'/>" />城市和区域
<s:doubleselect name="dlyTypeVO.frpVO.city"
id="dlyTypeVOfrpVOcity" list="cityMap.keySet()"
doubleName="dlyTypeVO.frpVO.area"
doubleId="dlyTypeVOfrpVOarea"
doubleList="cityMap[top]" headerKey=""
headerValue="请选择" />
一般的jsp标签关联的例子楼主可以参考一下,希望对楼主有帮助
<html>
<head>
<title>级联下拉菜单</title>
<meta http-equiv = "Content-Type" counter = "text/html;charset = gb2312">
<script>...
var nMaxLength = 0;
function init(obj)
...{
var hasChild = false;
var nodes = document.getElementsByTagName('p');
var selectobj;
var pid = (obj==undefined) ? 0 : parseInt(obj.value);
var selectobj = document.createElement('select');
selectobj.setAttribute('name','select_' + nMaxLength);
selectobj.onchange = function()
...{
var sels = document.getElementsByTagName('select');
for(var j=sels.length-1;j>0;j--)
...{
if(sels[j]==this)
...{
break;
}
nMaxLength--;
document.getElementById('div1').removeChild(sels[j]);
}
init(this);
}
for(var i=0;i<nodes.length;i++)
...{
var thispid = parseInt(nodes[i].getAttribute('pid'));
var id = parseInt(nodes[i].getAttribute('id'));
var n = nodes[i].getAttribute('n');
if(thispid == pid)
...{
var opt = document.createElement('option');
opt.setAttribute('value',id);
opt.innerText = n;
selectobj.appendChild(opt);
hasChild = true;
}
}
if(hasChild)
...{
nMaxLength++;
document.getElementById('div1').appendChild(selectobj);
init(selectobj);
}
}function getMaxLength()
...{
document.forms[0].maxLength.value = nMaxLength;
return true;
}</script>
</head>
<body onload = "init();">
<form action ="" method="post" onsubmit="return getMaxLength();">
<div id="div1">
<p n='product' id='0' pid='-1' /><p n='art' id='1' pid='0' /><p n='english' id='2' pid='0' /><p n='game' id='3' pid='0' />
<p n='math' id='4' pid='0' /><p n='natural' id='5' pid='0' /><p n='operate' id='6' pid='0' />
<p n='poem' id='7' pid='0' /><p n='science' id='8' pid='0' /><p n='high' id='11' pid='1' />
<p n='low' id='12' pid='1' /><p n='middle' id='13' pid='1' /><p n='abc' id='21' pid='2' />
<p n='number' id='22' pid='2' /><p n='song' id='23' pid='2' /><p n='story' id='24' pid='2' />
<p n='talk' id='25' pid='2' /><p n='listen' id='251' pid='25' />
<p n='read' id='252' pid='25' /><p n='word' id='253' pid='25' />
<p n='write' id='254' pid='25' /><p n='test' id='44' pid='1' /><p n='high' id='41' pid='4' />
</div>
<input type="hidden" name="maxLength" value="">
</form>
</body>
</html>其实方法应该都一样的,希望对楼主有帮助