1.Jquery动态添加select后台代码:
String comboSelect = "<select id=\"menuSelect\"
name=\"menuNo\">";
for (DemoEntity entity : entityList) {
comboSelect += "<option value=\""
+ entity.getOid() + "\">" + entity.getMenuName() +
"</option>";
}
comboSelect += "<option
value=\"0\">其他</option></select>";
response.setContentType("text/html;charset=UTF-8");
try {
response.getWriter().println(comboSelect);
} catch (IOException e) {
e.printStackTrace();
}
2.JQuery Ajax代码:
$.ajax({
url:
'#',
method:
'post',
success:
function(msg){
$("#menu").html(msg);
//为select添加change事件
$("#menuSelect").bind("change",function(){
alert($(this).val());
});
}
});