jquery下拉列表框动态值获取
一、引用jquery.js 示例:
<SCRIPT type="text/javascript" src="js/jquery.js"></SCRIPT>
二、jsp下拉列表框值得获取
//下拉框值获取
function SelectValue(){
alert("selectvalue");
$.post("newsAction_getLx.action",function(data){
var types=eval(data);
for(var i=0;i<types.length;i++){
$("#selectlx").append("<option value="+types[i].id+">"+types[i].type+"</option>")
}
});
}
三、action类
三、action类
/**
* 获取类型id、name
* @return
*/
public String getLx(){
try {
ServletActionContext.getRequest().setCharacterEncoding("utf-8");//防止乱码出现
ServletActionContext.getResponse().setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
String depts=newDao.getLx();
try {
ServletActionContext.getResponse().getWriter().write(depts);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
四、service类
/**
* 获取类型id、name
* @return
*/
public String getLx(){
Connection conn=Tool.getConnection();
PreparedStatement preStat = null ;
ResultSet rs = null ;
String types="[";
String sql="select id,type from MH_NEWS_TYPE";
try {
preStat=conn.prepareStatement(sql);
rs=preStat.executeQuery();
while(rs.next()){
types+="{'id':'"+rs.getString(1)+"','type':'"+rs.getString(2)+"'},";
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
Tool.release(rs , preStat , conn);
}
return types.substring(0,types.length()-1)+"]";
}
相关推荐
周公周金桥 2020-09-06
大象从不倒下 2020-07-31
AlisaClass 2020-07-19
MaureenChen 2020-04-21
xingguanghai 2020-03-13
teresalxm 2020-02-18
木四小哥 2013-05-14
SoShellon 2013-06-01
Simagle 2013-05-31
羽化大刀Chrome 2013-05-31
waterv 2020-01-08
LutosX 2013-07-29
vanturman 2013-06-27
wutongyuq 2013-04-12
luoqu 2013-04-10
today0 2020-09-22
89520292 2020-09-18
bigname 2020-08-25