I am a B person and don’t know how to use videos to solve the problem, so I have to use my confusing words to write.
Under normal circumstances, this situation is useful for secondary directories. There are many kinds of JS circulating on websites now, but they are all nothing more than those JS codes that make people like me confused. . All at once for... all at once array.
Without further ado, let’s get to the point.
First you have to create a table. Of course, if the directory has already been created in your table, this step can be omitted. But there is one thing to remind you: this table is the basis for my example (I don’t know if this is correct).
Since the table I use is ACCESS, I won’t go into creating the table. I will only list the corresponding field names of these two tables (database name: db.mdb):
Table name: type_tree - Parent class field: type_id (automatic number) type_name (category name)
Table name: s_type - Subclass field: id (automatic number) s_name (subcategory name) type_id (parent class ID) - and Corresponding to the parent class table,
the database connection is now established:
Dim conn, connStrSet conn = server.CreateObject("ADODB.Connection")connStr = "Provider = Microsoft.jet.oledb.4.0;"connStr = connStr & "Data Source = " & server.mappath("db.mdb")Conn.Open connStr
There should be no need to explain the above codes, they are all commonly used codes. .
Now onto the real action :)
Secondary context menus are generally made with drop-down menus, and I am no exception here, and I also use drop-down menus to make them.
But there's one thing that's different here.
One uses a jump menu. This is very important. The success depends entirely on whether the menu is used correctly!
Below is the code for this jump menu!
<select name="first" onChange="MM_jumpMenu('parent',this,0)">
<%
sql = "select [type_id],[type_name] from [type_tree]"
set rs = conn.execute(sql)'Get the ID and name of the parent class
if rs.eof or rs.bof then
response.write "<option>-----</option>" 'If there is no record, display -----
else
while not(rs.eof or rs.bof) 'If there is a record, list the parent name to form a drop-down.
response.write ("<option value='?sec=" & rs(0) & "'")
if cstr(rs(0)) = request.querystring("sec") then
response.write "selected"
end if
response.write (">" & rs(1) & "</option>")
rs.movenext
wend
rs.movefirst 'Move the cursor to the first item for later use.
end if
%>
</select>
Oh, by the way, there is another piece of code that I forgot to post. This is the key to jumping to the menu. Look at my carelessness!
Add to add:
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
The above code is pasted into <head> and is generated by DW. I don’t quite understand what it means, so I won’t comment it out :D
Now it is the secondary part of the menu. This is not a jump menu, it is just a list, so the only difference between the code and the jump menu above is the onchange function.
The following is the code of this menu. Since the loop and judgment are more complicated than the above, everyone should read it clearly.
<select name="second">
<%if rs.eof or rs.bof then
response.write ("<option>--------</option>")
else
if request.querystring("sec") = "" then 'Get the sec value after the jump
temp=rs(0) If it is empty, set the value of temp to the value of the first record
else
temp = request.querystring("sec") 'Otherwise it will be the received value
end if
subsql = "select [s_name] from [s_type] where type_id='"&temp&"'"
set subrs = conn.execute(subsql) 'List all records whose data is temp
if subrs.eof or subrs.bof then
response.write ("<option>-----</option>")
'If there is no record, display "-----" in this list
else
while not(subrs.eof or subrs.bof)' Otherwise, use a loop to list all records that meet the conditions.
response.write ("<option value=" & subrs(0) & ">" & subrs(0) & "</option>")
subrs.movenext
wend
end if
end if
'Close all record sets
subrs.close
set subrs = nothing
rs.close
setrs=nothing
conn.close
set conn = nothing
%>
</select>
Up to now, the creation process of this secondary menu has been completed. It is very simple as I explained.
If you don’t understand, please stop talking. Anyway, I don’t know what to say anymore.
The experts are willing to give you advice.