Simple Example of JS second-level and multi-level linkage

Source: Internet
Author: User

Simple Example of JS second-level and multi-level linkage

This article mainly introduces simple examples of super-simple JS second-level and multi-level linkage. If you need some help, please refer to them.

Super simple JS Code linkage, but to be used with jquery, you can also modify the code of the JS library by yourself.

The Code is as follows:

<Tr>

<Th> Level 1 Classification </th> <td>

<Select name = "subsidiary_cat_id" class = "subsidiary_cat_id" onchange = "linkage ('. subsidiary_cat_id', '. cat_id');">

<Option> select </option>

</Select>

<Script language = "javascript">

Var linkage_data = {$ list_file_category}; // initialize cascade data. {$ list_file_category} is the JSON_ENCODE data of PHP. The array has three pieces of data: id, parent_id, name

Function linkage (parent_dom, son_dom ){

Var parent_id = 0;

If (parent_dom ){

Parent_id = $ (parent_dom). val ();

}

$ (Son_dom). empty (); // clear the drop-down list first.

Var html = '<option> select </option> ';

$. Each (linkage_data, function (key, value ){

If (value. parent_id = parent_id ){

Html + = "<option value = '" + value. id + "'>" + value. name + "</option> ";

}

});

$ (Son_dom). append (html );

}

Linkage ('',". subsidiary_cat_id ") // if no parent node is uploaded, the first level of data is returned.

</Script>

</Td> </tr>

<Tr> <th> Level 2 Directory </th> <td>

<Select name = "cat_id" class = "cat_id">

<Option> select </option>

</Select> </td> </tr>

 

 

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.