首页 > 代码库 > ajax 为 select 赋值

ajax 为 select 赋值

html 页面
<
tr> <td class="dc-form-left">权限组:</td> <td class="dc-form-right"> <select name="group_id" class="form-control" id="group_id" style="width: 300px;"> @if($permission_list) @foreach($permission_list as $val)   <option value="{{$val[‘id‘]}}" @if($group_id == $val[‘id‘] ) selected @endif>{{$val[‘name‘]}}</option> @endforeach @endif </select> </td> </tr>
jquery 代码

$(document).on(‘change‘, ‘select[name=type]‘, function(){ $.get(‘/permission_list‘, { type: $(‘select[name=type]‘).val() }, function(res){ var group = $("#group_id"); group.empty(); for(var i=0;i<res.length;i++) { group.append("<option value=http://www.mamicode.com/‘"+res[i].id+"‘>"+res[i].name+"</option>"); } }); });

 

ajax 为 select 赋值