Write the JavaScript code, the display of the control menu

xiaoxiao2021-04-01  251

Fourth, write the JavaScript code, the display of the control menu

In fact, there is experienced programmer, you should know how to do it. But you may wish to read, maybe, the author's method is not necessarily a new attempt. Moreover, according to me guess, most of the people who read my article is the programmer who has no experience, huh, homes to help people. Come on, let's go. Let the menu appear, there are several ideas. By using the ASP and other programs directly generate the framework.

Ok, let's start from the load page (Document), step by step, the JavaScript code is how to control the display of the menu.

Since there are three menus, then we have to design such an HTML code in advance (it doesn't matter if it doesn't matter, it is just for your convenience):

You may ask, what data is there? Don't be strange, wait for you to understand. Let's take a look at the ONLOAD event of the object body_onload ()?

Let's study it. First, the program uses the getParent () function to get the container TD object handle of S0, then use the MAKMENU () function to generate the menu code, assign the code to the TD object just obtained; then S1, then S2 .. The getParent () function is defined as follows: Function getParent (src, tag) {if (src && src.tagname! = Tag) {return (getParent (src.parentelement, tag));} Return Src;} The TAG parameter here must be capitalized For example, TD, TR, TABLE, the function returned to the parent object defined by the Tag tag specified by the SRC. We must specifically explain the MakeMenu () function. This function is self-evident - generating the HTML definition of the menu, first look at the function definition:

Code Copy frame Function Makemenu (Arrsub, PValue, Cvalue, Name, BULSKIP) {

Var Shtml = " menu; BULSKIP, the default display item for the specified menu is "" or specific data.

The purpose of the GetSelectValue () function is to get the value of the Object of Object:

Ok, let's check it again, and there is any omissions. Select the unit from the first drop-down menu, immediately, the second drop-down menu and the third drop-down menu have changed to see if it is. (Not? Oh, look back "; select the department in the second drop-down menu to see if the staff's drop-down menu changes? Congratulations, you have successfully realized a three-dimensional pull-down menu. In fact, for the two-dimensional menu, the implementation method is exactly the same. The reader can use the method of this article to implement the full Raiders of the web project menu. I will encounter similar problems in the future. I think this time you will definitely say anything, let me get it.

Function setSubmenu (pselect) {

Var OOPTION, SVALUE;

IF (Pselect.SelectedIndex <0) Return;

Switch (pselect.name) {

Case "S0":

VAR TD = GetParent (Document.all ("S1"), "TD");

Td.innerhtml = MakeMenu (ArrDept, GetSelectValue ("S0"), "0", "S1", 0);

TD = getParent (Document.all ("S2"), "TD");

Td.innerhtml = MakeMenu (Arremp, GetSelectValue ("S1"), "0", "S2", 0);

Break;

Case "S1":

VAR TD = getParent (Document.all ("S2"), "TD");

Td.innerhtml = MakeMenu (Arremp, GetSelectValue ("S1"), "0", "S2", 0); Break;

DEFAULT:

}

}

Function getSelectValue (Oselect) {

IF (Oselect.SelectedIndex <0) returnograph;

Return Oselect.Options (Oselect.selectedIndex) .value;

}

Function Makemenu (Arrsub, PValue, Cvalue, Name, BULSKIP) {

Var Shtml = "

CopyRight © 2020 All Rights Reserved
Processed: 0.050, SQL: 9