<% ShiModel model = new ShiModel(); ShiManagerImpl manager = new ShiManagerImpl(); AreaModel areaModel = new AreaModel(); AreaManager areaManager = new AreaManagerImpl(); List dataList = null,areaList=null; String sql = "select * from area order by id desc"; dataList = manager.getShiInfo(); areaList = areaManager.getAreaList(sql); %> <script language="javaScript" src="/js/common.js" ></script> <script Language="JavaScript"><!-- var onecount; onecount=0; subcat = new Array(); <% int count=0; while(count<dataList.size()){ model =(ShiModel) dataList.get(count); %> subcat[<%=count%>] = new Array("<%=model.getShiName()%>","<%= model.getShengId()%>","<%= model.getShiId()%>"); <% count++; } %> onecount =<%=count%>; //第二级下拉 function changelocation(locationid) { document.companyForm.shiid.length = 0;
var locationid=locationid; var i; for (i=0;i < onecount; i++) { if (subcat[i][1] == locationid) { document.companyForm.shiid.options[document.companyForm.shiid.length] = new Option(subcat[i][0], subcat[i][2]);
} }
//changelocation1(subcat[i][2]); } //第三级下拉 var twocount; twocount=0; subcate1=new Array(); <% count = 0; while(count<areaList.size()){ areaModel = (AreaModel)areaList.get(count); %> subcate1[<%=count%>]=new Array("<%=areaModel.getAreaName().trim()%>","<%=areaModel.getShiid()%>","<%=areaModel.getId()%>"); <%count++;}%> twocount=<%=count%> function changelocation1(shiid){ document.companyForm.quid.length=0; var shiid=shiid; var i; for(i=0;i<twocount;i++){ if(subcate1[i][1]==shiid){ document.companyForm.quid.options[document.companyForm.quid.length]=new Option(subcate1[i][0],subcate1[i][2]); } } }
<% ShengModel smodel = new ShengModel(); ShengManagerImpl smanager = new ShengManagerImpl(); List arrayList = smanager.getShengInfo(); if(arrayList==null||arrayList.size()<1){ %> <tr><td>请先添加栏目</td></tr> <%}else{%> <tr> <td width="14%">所属省份:</td> <td colspan="2">
//第二级下拉 function changelocation(locationid) { document.companyForm.shiid.length = 0;
var locationid=locationid; var i; for (i=0;i < onecount; i++) { if (subcat[i][1] == locationid) { document.companyForm.shiid.options[document.companyForm.shiid.length] = new Option(subcat[i][0], subcat[i][2]);
<%
ShiModel model = new ShiModel();
ShiManagerImpl manager = new ShiManagerImpl();
AreaModel areaModel = new AreaModel();
AreaManager areaManager = new AreaManagerImpl();
List dataList = null,areaList=null;
String sql = "select * from area order by id desc";
dataList = manager.getShiInfo();
areaList = areaManager.getAreaList(sql);
%>
<script language="javaScript" src="/js/common.js" ></script>
<script Language="JavaScript"><!-- var onecount;
onecount=0;
subcat = new Array();
<%
int count=0;
while(count<dataList.size()){
model =(ShiModel) dataList.get(count);
%>
subcat[<%=count%>] = new Array("<%=model.getShiName()%>","<%= model.getShengId()%>","<%= model.getShiId()%>");
<%
count++;
}
%>
onecount =<%=count%>;
//第二级下拉
function changelocation(locationid)
{
document.companyForm.shiid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.companyForm.shiid.options[document.companyForm.shiid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
//changelocation1(subcat[i][2]);
}
//第三级下拉
var twocount;
twocount=0;
subcate1=new Array();
<%
count = 0;
while(count<areaList.size()){
areaModel = (AreaModel)areaList.get(count);
%>
subcate1[<%=count%>]=new Array("<%=areaModel.getAreaName().trim()%>","<%=areaModel.getShiid()%>","<%=areaModel.getId()%>");
<%count++;}%>
twocount=<%=count%>
function changelocation1(shiid){
document.companyForm.quid.length=0;
var shiid=shiid;
var i;
for(i=0;i<twocount;i++){
if(subcate1[i][1]==shiid){
document.companyForm.quid.options[document.companyForm.quid.length]=new Option(subcate1[i][0],subcate1[i][2]);
}
}
}
<%
ShengModel smodel = new ShengModel();
ShengManagerImpl smanager = new ShengManagerImpl();
List arrayList = smanager.getShengInfo();
if(arrayList==null||arrayList.size()<1){
%>
<tr><td>请先添加栏目</td></tr>
<%}else{%>
<tr>
<td width="14%">所属省份:</td>
<td colspan="2">
<select style="width:90px;height:20px;" name="shengid" size="1" id="shengid" onChange="changelocation(document.companyForm.shengid.options[document.companyForm.shengid.selectedIndex].value)">
<option selected="selected" value="0">请选择省份</option>
<%for(int i=0;i<arrayList.size();i++){
smodel =(ShengModel) arrayList.get(i);
%>
<option value="<%=smodel.getShengId()%>"><%=smodel.getShengName()%></option>
<%}}%>
</select>
所属城市:
<select style="width:90px;height:20px;" name="shiid" id="shiid" onChange="changelocation1(document.companyForm.shiid.options[document.companyForm.shiid.selectedIndex].value)">
<option selected="selected" value="0">请选择城市</option>
</select>
所属县区:
<select style="width:90px;height:20px;" name="quid">
<option selected="selected" value="0">请选择县区</option>
</select>
<font color="#FF0000"> </font></td>
</tr>
所属县区:
<select style="width:90px;height:20px;" name="quid">
<option selected="selected" value="0">请选择县区</option>
</select>
<script>
//在这加上下面的内容试试,或者再加上其他相关的东东changelocation1(document.companyForm.shiid.options[document.companyForm.shiid.selectedIndex].value)
</script>
一般情况下,第一个换选了,第二个下拉框(B)会选择第一个内容,你直接那个B的第一个id传过去就是了这和六楼方法不一样
所属城市:
<select style="width:90px;height:20px;" name="shiid" id="shiid" onPropertyChange="changelocation1(document.companyForm.shiid.options[document.companyForm.shiid.selectedIndex].value)">
<option selected="selected" value="0">请选择城市</option>
</select>
//第二级下拉
function changelocation(locationid)
{
document.companyForm.shiid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.companyForm.shiid.options[document.companyForm.shiid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
//changelocation1(subcat[i][2]);
} 我知道你的意思,我怎么捕获到第一个i呢,然后调用changelocation1(subcat[i][2]);
我应该放在哪里呢?
与这个省id对应的市的数组是不是可以确定了,
这个市数组确定了,那么,取这个市的数组的第一个值的id,传给选择市的那个函数,你看看行得通不六楼的方法是以为第一次出现的情况,在你这种情况下不可用
<option selected="selected" value="0">请选择城市</option>
<option value="1">厦门市</option>
</select> 加了“请选择城市”,这样即使只有“厦门市”一个,也能产生值改变事件了