I have been studying DOM programming for a long time. This is the most fulfilling part of my experience. Instructor Bi has carefully explained the relevant knowledge to us, I also found a lot of excellent web pages on the Internet as examples to explain to us and explain a lot of methods on how to learn DOM. I think it is really beneficial.
The following are some examples that I think are better.
1. Level-2 linkage drop-down menu (level-1 is a province, level-2 is a city, and level-1 is required to select a province, level-2 cities correspond to appear)
Step: 1) Basic Framework (HTML): There are two check boxes, and there should be no options in the second check box. Note that the first drop-down box will be used as the event source, the onchange method is used to stimulate the function implementation in JavaScript.
The Code is as follows:
<BR> <select id = "province" onchange = "selCity () "> <BR> <option> -- select a province -- </option> <BR> <option> Beijing </option> <BR> <option> Tianjin </option> <BR> <option> Hubei </option> <BR> <option> Shandong </option> <BR> <option> Hebei </option> <BR> </select> <BR> <select id = "city"> <BR> <option> -- select a city -- </option> <BR> </select> <BR>
2) There is no need to modify the page. You just need to display one in the drop-down menu.
3) JavaScript is used to implement the function. If you want to select a province from the first drop-down list, the corresponding city will be directly displayed, first, we thought of the map set container, but the JavaScrip does not have a map set. Then we thought of an array container and finally decided to use a two-dimensional array to help us implement this function.
The Code is as follows: