Home > Web Front-end > JS Tutorial > How to achieve select select secondary linkage effect

How to achieve select select secondary linkage effect

一个新手
Release: 2017-09-22 09:00:10
Original
3351 people have browsed it

<li style="margin-right:-5px">一级类目:
                    <select id="mainCategoryId" name="mainCategoryId" class="length_2" onchange="changeCate()">
                        <option value="">---请选择---</option>
                        #foreach($cell in $categories)
                            <option value="$!{cell.id}"  #if($!cell.id ==  $!query.mainCategoryId) selected #end >$!{cell.name}</option>
                        #end
                    </select>
                </li>
                <li style="margin-right:-5px">二级类目:
                    <select class="categoryId" name="categoryId" class="length_2">
                        <option value="">---请选择---</option>
                    </select>
                </li>
Copy after login
function changeCate(){    
 var  mainCategoryId = 
$("#mainCategoryId").find("option:selected").val();   
 if(mainCategoryId == "") {        
 $(".categoryId").empty().append("<option value=&#39;&#39;>---请选择---</option>");        
 return false;
    }    
 $.ajax({       
     url:&#39;/tvtao/video/item/category.htm&#39;,        
     type:"post",        
     dataType:"json",        
     data: {&#39;_tb_token_&#39; : $("input[name=&#39;_tb_token_&#39;]").val(), parantId : mainCategoryId},        
     success: function (data) {            
     console.log(data);            
     $(".categoryId").empty().append("<option value=&#39;&#39;>---请选择---</option>");           
      for(var i = 0, len = data.length; i < len; i++)
            {                
            alert(data[i].id);                
            $(".categoryId").append($("<option value=&#39;" + data[i].id + "&#39;>" + data[i].name + "</option>"));
            }

        }
    });
}
Copy after login

The above is the detailed content of How to achieve select select secondary linkage effect. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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