jquery 动态遍历select 赋值的实例

获取select 选中的值:

$("#selDepUnit").children('option:selected').val();

Ajax 动态为select赋值:

$.ajax({
  type: "POST",
  url: "/department/findDepByPid",
  data:"pid="+pid,
  success: function (data) {
  $("#selDep").empty();
  $.each(data, function(i, item){ 
   $("#selDep").append($("<option/>").text(item.name).attr("value",item.id));
   }); 
  },
});

相关推荐