热门回答
可以先放到hidden域中,然后通过jquery先盯桐获取hidden域的值,然后用$("selectid"凯搏坦).val("hidden域银磨的值");
假码肆设select的ID为 aselect ,后台睁模缺获取的值为 test ,赋值语句为:悉辩
$("#aselect").val('test');
java code:
List<String> list = new ArrayList<String>();
list.add("冲派北京");
list.add("上海"碧判碧);
....
JSONArray jsonObject = JSONArray.fromObject(list);//导入json包
String jsonString = jsonObject.toString();
HttpServletResponse response = ServletActionContext.getResponse();
response .setCharacterEncoding("UTF-8");
PrintWriter pw =response .getWriter();
pw.write(jsonString);
pw.flush();
pw.close();
页面:
<script>
$(function(){
$('#b').click(function(){
$.post('XXX.action',null,function(data){
data = eval(data);
var obj = document.getElementById("s");
for(var i=0;i<data.length;i++){
obj.options[i]= new Option(data[i],i);
}
})
})
});
</script>
<button id="b">test</button>
<select id="s"悔举></select>
以上代码纯手写的,未测试!