Select tag drop-down list second-level linkage cascade instance code _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces the code of the Select label drop-down list second-level linkage cascade instance. For more information, see bind the drop-down list from the server, the text name of the level-2 drop-down is added with the ID of the level-1 drop-down according to certain rules.

The Code is as follows:


Var options = new Array ();
$ (Document). ready (function (){
// Second-level linkage
$ ('# DdlPages'). children ('option'). each (function (I ){
Options [I] =''+ $ (This). text () +'';
}); // Put the option List in the array
$ ('# DdlPages option: gt (0)'). remove (); // clear the drop-down list
$ ('# DdlSubsystems'). bind ('change', function () {// register an event
Var systemname = $ ('# ddlSubsystems option: selected'). text ();
For (var j = 0; j $ ('# DdlPages'). append (options [j]);
} // The option List is initialized first.
$ ('# DdlPages option: gt (0)'). each (function (I) {// traverse exclusion
Var textname = $ (this). text ();
Var index = textname. indexOf ('-' + systemname );
If (index <0 ){
$ (This). remove ();
} Else {
$ (This). text (textname. substring (0, index ));
}
});
$ ('# DdlPages'). val (0); // The first row is selected by default.
});
});

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.