jquery或js实现省市县三级联动下拉列表,要能用的带注释的最好,省市县数据从数据库中读出来的

jquery或js实现省市县三级联动下拉列表,要能用的带注释的最好,省市县数据从数据库中读出来的,第1张

那你要用Ajax分别远程调用了~这样做的话肯定会有延时~思路可以给你,但是代码就算了~太费劲了~而且要和后台交互

思路就是写一个函数,这个函数可以接受一个参数,这个参数就是你每次点选的那个值,然后通过AJAX把这个参数传给后台,通过数据库查出来之后把内容赋给二级列表,以此类推,不光可以三级联动,N级都可以~

看看我的,如果对你有用不要忘记加分哦!

---------------------------------------

数据库名(ACCESS):db2mdb

数据库表:diming

数据字段:

id 自动编号

sheng 文本,省名

shi 文本,市名

数据库记录内容如下图

链接数据库代码:自己写,我这个是包含connasp进来

---------------------------------------

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!--#include file="connasp"-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN" ">

<html>

<head>

<meta >

<META >

<title></title>

<%

dim count

set rs=connexecute("select  from diming")

%>

<script language="JavaScript">

var onecount=0;

subcat = new Array();

<%

count = 0

do while not rseof

%>

subcat[<%=count%>] = new Array("<%=rs("shi")%>","<%= trim(rs("sheng"))%>");

<%

count = count + 1

rsMoveNext

loop

//rsclose

%>

onecount=<%=count%>;

function changelocation(locationid)

{

documentform1shilength = 0;

documentform1shioptions[documentform1shilength] = new Option("-选择市-", "");

var locationid=locationid;

for (var i=0;i < onecount; i++)

{

if (subcat[i][1] == locationid)

{

documentform1shioptions[documentform1shilength] = new Option(subcat[i][0], subcat[i][2]);

}

}

function test(o) {

var index = oselectedIndex;

var text = ooptions[index]text;

documentgetElementById("shi1")value = text;

}

}

</script>

</head>

<body>

<%set rs=connexecute("select distinct(sheng) from diming where sheng in (select sheng from diming group by sheng having(count(sheng))>1)")' and id not in (select min(id) from diming group by sheng having count(sheng)>1)")%>

<form name="form1" method="post" action="">

<select name="sheng" onChange="changelocation(documentform1shengoptions[documentform1shengselectedIndex]value);" size="1">

<option selected value="-选择省-">-选择省-</option>

<%if rseof then%>

<option selected value=""></option>

<%else

do while not rseof%>

<option selected value="<%=rs("sheng")%>"><%=rs("sheng")%></option>

<%rsMoveNext

loop

end if

%>

</select>

<input type="text" name="question" style="width:10px;height:15px; position:absolute"><span style=" margin-left:150px;width:18px;border:0px solid red;"><select name="shi" id="shi" style="margin-left:-150px;width:80px;" onChange="documentform1questionvalue='documentform1questionoptions[documentformshiselectedIndex]text)';test(this)">

<option selected value="">-选择市-</option>

</select></span><input name="shi1" type="hidden" id="shi1">

</form>

</body>

</html>

<option value="1">12</option>

selected的值可以类似这样输出,参数自己根据实际调整

outprintln("<option value='"+dvgetDataid()+ "'>"+dvgetDataid()+"</option>");

以上就是关于jquery或js实现省市县三级联动下拉列表,要能用的带注释的最好,省市县数据从数据库中读出来的全部的内容,包括:jquery或js实现省市县三级联动下拉列表,要能用的带注释的最好,省市县数据从数据库中读出来的、asp省市联动问题、jsp 省市二级联动,在修改数据信息时省市下拉菜单显示的默认值数据库中的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10154271.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存