您的位置 >>> 星想互联 >>> 课堂教学 >>> 教学案例
JQUERY实现二级联动菜单
点击数:2638  发布时间2013-04-29 18:19:55

jquery页面:

<script src="jquery.min.js"></script>
<script>
$(function(){
 $("#typeid").change(function(){
  $.get("select_1.asp",{typeid:$(this).val()},
  function(data){
  data=eval("("+data+")");
  var mydata="";
  for( var i=0;i<data.length;i++){
  mydata+="<option value='"+data[i].deatilid+"'>"+data[i].detailname+"</option>"}
  
  $("#detailid").html(mydata)
  $("#rr").html(data.length)
  })
 }); 
 
 $("#typeid").change()
});


</script>
<%
response.Charset="gb2312"
sql="SELECT * FROM newsType"

set rs=conn.execute(sql)
%>
<select name="select" id="typeid">
<%do while not rs.eof%>
    <option value="<%= rs("typeid") %>"><%= rs("typename") %></option>
<%
rs.movenext
loop
%>
</select>

<select name="select" id="detailid">
</select>

 

数据页面:

<!--#include file="conn.asp" -->

<%
response.Charset="gb2312"
sql="SELECT * FROM detailType where typeid="&request.querystring("typeid")
'sql="SELECT * FROM detailType"

set rs=conn.execute(sql)

json_text="["

do while not rs.eof and not rs.bof
json_text=json_text+"{'detailid':"&rs("detailid")&",'detailname':'"&rs("detailname")&"'}"
rs.movenext
if not rs.eof then json_text=json_text&","
loop
rs.close
json_text=json_text+"]"
response.write json_text
 %>

来源:星想互联