動態賦值,默認選中哪項值

 
function showDep(){
$.ajax({
   type: "post",
   url: baseURL+"/productGroup/showDep.action",
   dataType: "json",
   success: function(date){
   var selectObj=document.getElementById("udep");
   selectObj.options.length=1; 
   for(var i=0;i<date.length;i++){
  var len = selectObj.length;
  selectObj.options[len] = new Option(date[i].name, date[i].id);
  if('${productGroup.series.id}' == date[i].id){
  selectObj.options[len].selected = true;
  }
   }
   }
}); 
}


<select style="width:175px;" name="productGroup.series.id" id="udep">

<option value="">————請選擇————</option>

</select> 

public void showDep()
{
HttpServletResponse response = getResponse();
String json;
String hqlSeries = "from ProductSeries as p where p.type = 1";
List listProdSeries = productSeriesServer.findList(hqlSeries);
json = JsonUtils.listToJSONString(listProdSeries); 
PrintWriter out;
try {
response.setCharacterEncoding("UTF-8");
out = response.getWriter();
out.write(json);
} catch (IOException e) {
e.printStackTrace();
}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章