Home Web Front-end JS Tutorial Ajax Json cascading menu implementation code_json

Ajax Json cascading menu implementation code_json

May 16, 2016 pm 06:43 PM
json Cascading menu

The first drop-down box:

Copy code The code is as follows:

<select id=" select" name="rawfoodBasic.category" onchange="doChange(this.value);">
//The value in the first drop-down box
</select>

Second drop-down box:
Copy code The code is as follows:

<select id ="subSelect" name="rawfoodBasic.absorb" onchange="javascript:alert(this.value);" > //If you want 3 menus, you can also write the corresponding time
<option value="0 ">--Please select the secondary menu-- </option>
</select>

js code:
Copy code The code is as follows:

<script type="text/javascript">
$.ajaxSetup({
cache: false
}); //Clear the previous value in ajax
function doChange(obj){
var url = '<c:url value="/nutrition/getSubDictDataToJsonByCategory.action"/>' "?rawfood.category=" obj;//The action entered after the first drop-down box is selected, and the required value of the second drop-down box is assigned in the action
$.getJSON(url,function(json){
var seleOjb=document.getElementById("subSelect");
for(var k=0;k<seleOjb.options.length;k ){
seleOjb.options.remove(k); //When When the value in the first drop-down box is selected again, clear the original value in the second drop-down box
}
$.each(json.subCategoryDictList,function(index,subDictData){
var optionj =document.createElement("option"); //Assign a value to the second drop-down box
optionj.value = subDictData.id;
//alert(subDictData.id);
optionj.text=subDictData .name;
seleOjb.add(optionj);
});
});
}
</script> 🎜>
Copy code
The code is as follows: <action name="getSubDictDataToJsonByCategory" class="rawfoodAction" method="getSubDictDataToJsonByCategory"> ; <result name="success" type="json"> <param name="includeProperties"> //Define the returned parameters
^subCategoryDictList[d ].id,
^subCategoryDictList[d ].name
</param>
</result>
</action>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between MySQL5.7 and MySQL8.0? What is the difference between MySQL5.7 and MySQL8.0? Feb 19, 2024 am 11:21 AM

What is the difference between MySQL5.7 and MySQL8.0?

Combination of golang WebSocket and JSON: realizing data transmission and parsing Combination of golang WebSocket and JSON: realizing data transmission and parsing Dec 17, 2023 pm 03:06 PM

Combination of golang WebSocket and JSON: realizing data transmission and parsing

How to exclude a field from JSON using @Expose annotation in Java? How to exclude a field from JSON using @Expose annotation in Java? Sep 16, 2023 pm 09:49 PM

How to exclude a field from JSON using @Expose annotation in Java?

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization tips for converting PHP arrays to JSON

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Nov 18, 2023 pm 01:59 PM

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string

Pandas usage tutorial: Quick start for reading JSON files Pandas usage tutorial: Quick start for reading JSON files Jan 13, 2024 am 10:15 AM

Pandas usage tutorial: Quick start for reading JSON files

How to handle XML and JSON data formats in C# development How to handle XML and JSON data formats in C# development Oct 09, 2023 pm 06:15 PM

How to handle XML and JSON data formats in C# development

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

How do annotations in the Jackson library control JSON serialization and deserialization?

See all articles