PHP implements secondary linkage menu

藏色散人
Release: 2023-03-06 09:32:02
Original
3950 people have browsed it

php method to implement the secondary linkage menu: first, according to the value of the large category, pass the value to the background PHP for processing through jQuery; then use PHP to query the MySQl database to get the corresponding small category; finally return the JSON data to Just front-end processing.

PHP implements secondary linkage menu

Recommended: "PHP Video Tutorial"

jq php mysql realizes secondary menu linkage

Secondary linkage drop-down menu selection is used in many places, such as province and city drop-down linkage, and product size drop-down selection linkage.

The effect achieved is that when a major category is selected, the option content in the small category drop-down box also changes accordingly. Implementation principle: According to the value of the major category, the value is passed to the background PHP for processing through jQuery. PHP queries the MySQl database to obtain the corresponding small category and returns JSON data to the front-end for processing.

html:

<label>大类:</label>
<select name="bigname" id="bigname"> 
<option value="1">前端技术</option> 
<option value="2">程序开发</option> 
<option value="3">数据库</option> 
</select> 
<label>小类:</label> 
<select name="smallname" id="smallname"> 
</select>
Copy after login

jQuery

<script>
    $(function(){ 
        getSelectVal(); 
        $("#bigname").change(function(){ 
            getSelectVal(); 
        }); 
    })
function getSelectVal(){ 
   $.getJSON("server.php",{bigname:$("#bigname").val()},function(json){                   
   var smallname = $("#smallname"); 
   $("option",smallname).remove();    
   $.each(json,function(index,array){                        
    var option = "<option > > value=&#39;"+array[&#39;id&#39;]+"&#39;>"+array[&#39;title&#39;]+"</option>";    
    smallname.append(option); 
    }); 
    }); 
 } 
</script>
Copy after login

php Obtaining data is to obtain small categories from the database based on the id of the large category, and then return it in json format.

The above is the detailed content of PHP implements secondary linkage menu. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!