Home > php教程 > php手册 > body text

Second-level linkage Third-level linkage Fourth-level linkage Multi-level linkage

WBOY
Release: 2016-09-02 08:42:19
Original
2282 people have browsed it

php thinkphp realizes second-level linkage, third-level linkage, fourth-level linkage, multi-level linkage, attachment with database and selection.
If there is something wrong, you are welcome to give us guidance and we can learn and make progress together.
Sharing is a virtue.
Page: <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script><br> <!-- If you do not want to keep the selected state, you can remove the contents of the <if></if> tag --><br> <!-- Each choice is a level one. You can have only two choices, which is a level two linkage, three is a level three linkage, four is a level four linkage, and so on. I made a level four linkage and a level two linkage. Normal --><br> <br> <!-- Region --><br> <div class="form-group"> <br> <label class="col-sm-2">Laboratory region</label><br> <div class="btn-group" style="margin-bottom: 20px;"> <br> <select name="region1_id" id="region_0_0" onchange="setregion(0,0)" class="form-control" style="display:inline; width:auto;"><br>             <option name="selected" selected value="-1">City</option> <br>           <volist name="list" id="vo"><br> <option value="{$vo['id']}" condition="$row['region1_id'] eq $vo['id']">selected='selected' >{$vo['title']}</option> <br>                                                                                         </volist></select><br> <select name="region2_id" id="region_1_0" onchange="setregion(1,0)" class="form-control" style="display:inline; width:auto;"><br>             <option name="selected" selected value="-1">School</option> <br>                                                                                                                                                                                                   ?            <if condition="$row['region2_id'] neq NULL"><br>                                                                                                    $region2 = D('LabTypeRegion')->where(array('id'=>$row['region2_id']))->getField('title');<br>                                                                                                             <option value="{$row['region2_id']}" selected style="display:none;">{$region2}</option> <br>                                                                                                                                                                                                                                                                                       ? </if></select><br> <select name="region3_id" id="region_2_0" onchange="setregion(2,0)" class="form-control" style="display:inline; width:auto;"><br>            <option name="selected" selected value="-1">College</option> <br>                                                                                                                                                                                                   ?            <if condition="$row['region3_id'] neq NULL"><br>                                                                                                    $region3 = D('LabTypeRegion')->where(array('id'=>$row['region3_id']))->getField('title');<br>                                                                                                         <option>{$region3}</option> <br>         </if><br>         <!-- 保持上回选中 --><br>     </select><br>     <select><br>         <option>实验室</option> <br>         <!-- 保持上回选中 --><br>         <if><br>           <php><br>               $region4 = D('LabTypeRegion')->where(array('id'=>$row['region4_id']))->getField('title');<br>           </php><br>           <option>{$region4}</option> <br>         </if><br>         <!-- 保持上回选中 --><br> <br>     </select><br>   </div> <br> </div> <br> <script type="text/javascript">//Set the default and restore the default option when the page is loaded. <br /> Function region_default() {<br />          $("option[value='-1']").attr('selected', 'selected');<br /> }<br /> Function setregion(num, address_id) {<br />       var next = num + 1;<br />           $.ajax({<br />            type: 'POST',<br />                     //Set the json format and receive the returned array. <br /> DataType: 'json',<br />    url: '',<br /> ​​​​​​ //ajax passes the value of the current option, which is the current region_id. <br /> data: 'region_id=' + $('#region_' + num + '_' + address_id).val(),<br /> Success: function(msg) {<br />                          // Execute if the return value is not empty. <br /> If (msg != null) {<br />                                                                                                                                                                                                                                                  // Loop to write the content to be added to the next select. and add name tag. <br /> for (var i = 0; i < msg.length; i++) {<br />                  option_str+='<option name="region_'+next+'"value="'+msg[i].id+'">'+msg[i].title+'';<br />                     }<br /> //Delete the content marked with name next in the next select. <br />                         $("option[name='region_" + next + "']").remove();<br /> // Add the written content to the next select. <br />                          $('#region_' + next + '_' + address_id).append(option_str);<br />                                                                                                                                                                                                                        ‐—   //If the return value is empty, remove all marked options and restore the default options. <br /> for (var i = next; i <= 4; i++) {<br />                         $("option[name='region_" + i + "']").remove();<br />                     }<br />                 }<br />              }<br /> <br />          })<br /> }<br /> </script><br><!-- 地域 -->控制器:    /**<br> * [labindex multi-level linkage]<br> * @return [type] [description]<br> ​​*/<br>     public function labindex(){<br>         //实验室地域<br>         $d=D('LabTypeRegion');<br>         if(IS_POST){<br>             if($_POST['region_id']){<br>                 $region_id = $_POST['region_id'];<br>                 $condition['pid'] = $region_id;<br>                 $list = $d->where($condition)->select();<br>                 // echo json_encode($list);<br>                 $this->ajaxReturn($list);<br>             }<br>         }else{<br>             $condition['pid'] = array('neq',0);<br>             $condition['level'] = 1;<br>             $list = $d->where($condition)->select();<br>             $this->assign('list',$list);<br> <br>         }<br>         //实验室地域<br> <br>         $this->display();<br>     }

Second-level linkage Third-level linkage Fourth-level linkage Multi-level linkage 多级联动.zip ( 3.31 KB 下载:8 次 )

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 Recommendations
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!