How to Implement the brushless newest linkage menu in parsing JS (1)

Source: Internet
Author: User

This article briefly introduces the linkage menu and JS Implementation of the select method for the brushless newest linkage menu. In fact, the implementation principle of the Linkage menu is very simple, this article describes in detail how to implement the linkage menu. Once we know the principle, we can easily create an infinitely interactive menu loaded from XML and database.

JS Implementation of the select method for the brushless newest linkage menu)

The linkage menu is the option in the next drop-down Box Based on the selected value in the previous drop-down box. A typical application is the provincial/municipal linkage menu, the city drop-down options are determined based on the province you choose. We often encounter similar requirements. I believe many new users are troubled by this problem.

In fact, the implementation principle of the Linkage menu is very simple. This article describes the implementation method of the Linkage menu in detail. Knowing the principle, we can easily create an infinite linkage menu loaded from XML and database.

Implementation of the Linkage menu:

1. Confirm the data format:

First, we will introduce the syntax for creating an Option:

Code:

 
 
  1. varnewOption=newOption(optionText,optionvalue);  
  2.  

According to the above syntax, we know that the select option is divided into optionText and optionvalue. optionText is the option we see in the drop-down box, while optionvalue is the actual submitted value. For example, if an option is "Beijing", the actual submitted value is "010 ".

To maintain consistency, we confirm that the options are in the following format:

Code:

 
 
  1. {Txt: "option name", val: "option value "}
  2.  

Then a rule group is:

Code:

 
 
  1. VarchildArr = [];
  2. ChildArr ['parent option value 1'] = [
  3. {Txt: "option 1", val: "option value 1 "},
  4. {Txt: "option 2", val: "option value 2 "},
  5. {Txt: "option name 3", val: "option value 3 "},
  6. ...
  7. {Txt: "option name n", val: "option value n "}
  8. ]
  9. ChildArr ['parent option value 2'] = [
  10. {Txt: "option 1", val: "option value 1 "},
  11. {Txt: "option 2", val: "option value 2 "},
  12. {Txt: "option name 3", val: "option value 3 "},
  13. ...
  14. {Txt: "option name n", val: "option value n "}
  15. ]
  16.  

The "parent option value" is the value selected from the parent drop-down list.

Note: The values in [] and {} are separated by commas (,), but the last value cannot be followed by commas (,). Otherwise, the syntax is incorrect, special attention should be paid to PHP programmers !!!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.