永发信息网

谁能帮我解释这个下拉菜单 联动的代码吗~~

答案:1  悬赏:50  手机版
解决时间 2021-05-10 20:24
  • 提问者网友:你独家记忆
  • 2021-05-09 23:40

<script language = "JavaScript">
<%
Set Rs = Server.CreateObject("Adodb.Recordset")
Rs.Open "SELECt * FROM products_category_sub ORDER BY sub_id asc", conn, 1, 1
%>
var onecount;
onecount=0;
subcat = new Array();
<%
i = 0
Do While Not Rs.EOF
%>
subcat[<%=i%>] = new Array("<%= Trim(Rs("sub_title"))%>","<%= Rs("main_id")%>","<%= Rs("sub_id")%>");
<%
i = i + 1
Rs.MoveNext
Loop
Rs.Close
%>
 
onecount=<%=i%>;

function changelocation(locationid,formname)
    {
    formname.sub_id.length = 0;

    var locationid = locationid;
    var i;
    for (i = 0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            {
             formname.sub_id.options[formname.sub_id.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
       
    }
</script>

……
……

……

<select name="main_id" id="main_id" onchange="changelocation(document.products_add.main_id.options[document.products_add.main_id.selectedIndex].value,document.products_add)">
                          <%
i = 0
Set RsBig = Conn.Execute("SELECT * FROM products_category_main ORDER BY order_id")
Do While Not RsBig.EOF
    If i = 0 Then main_id = RsBig(0)
    Response.Write("<option value="""&RsBig(0)&""">"&RsBig(1)&"</option>")
    i = i + 1
    RsBig.MoveNext
Loop
Set RsBig = Nothing
%>
                        </select>
                          <select name="sub_id" id="sub_id">
                            <%
If main_id <> "" Then
    Set RsSmall = Conn.Execute("SELECT * FROM products_category_sub WHERe main_id = "&main_id)
    Do While Not RsSmall.EOF
        Response.Write("<option value="""&RsSmall(0)&""">"&RsSmall(1)&"</option>")
        RsSmall.MoveNext
    Loop
End If
Set RsSmall = Nothing

%>
                        </select>

最佳答案
  • 五星知识达人网友:一叶十三刺
  • 2021-05-10 00:55
与普通的下拉脚本菜单差不多,最大的不同点在于,他所链接的文字是来源于数据库,比如一个网站的下拉菜单选项时常改变,这样的话,只要在后台设置下来选项,前台的下拉菜单会自动改变。方便使用
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯