Ajax Json cascading menu implementation code_json
May 16, 2016 pm 06:43 PMThe first drop-down box:
<select id=" select" name="rawfoodBasic.category" onchange="doChange(this.value);">
//The value in the first drop-down box
</select>
Second drop-down box:
<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:
<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> 🎜>
</param>
</result>
</action>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

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

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

Pandas usage tutorial: Quick start for reading JSON files

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

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