jquery 给下拉框赋值

jquery代码

 1 $('.edit-modal').on('click',function(){
 2         var id = $(this).attr('href');
 3         var value = $(this).attr('value');
 4         // get data
 5         var url="<?php echo $root;?>/editRobotActionNum";
 6         $.ajax({
 7             url: url,
 8             data: 'id='+value,
 9             type : 'POST',
10             dataType : 'json',
11             success : function(json)
12             {
13                 $('#editId').attr('value',json.id);
14                 $('select#edit_material_id').val(json.material_id);
15                 $('select#edit_station_id').val(json.station_id);
16                 $('#edit_up_action').attr('value',json.up_action);
17                 $('#edit_turn_action').attr('value',json.turn_action);
18                 $('#edit_down_action').attr('value',json.down_action);
19                 
20             }
21         });
22 
23         $(id).modal('show');
24     });

html

1 <select class="form-control" id="edit_material_id" name="material_id">
2     <option value=""></option>
3     <?php foreach($stock_info as $row):?>
4         <option value="<?php echo $row['id'];?>"><?php echo $row['name'];?>    </option>
5     <?php endforeach;
6 </select>

 

posted @ 2017-03-13 21:20  zbchls  阅读(15839)  评论(1编辑  收藏  举报