getLines('${param.qlineId}','${param.qsectionId}');
getSections('${param.qlineId}','${param.qsectionId}');
getWokPoints('${param.qsectionId}','${param.qworkPointId}');
<select id="qlineId" name="qlineId" onchange="getSections(this.value,'')"> ////select默认值的设置
方法1<option value=" " selected>666</option>
方法2<option
value=" " selected=“selected”>666</option>
后台
public
ActionForward getLines(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response){
Map map =initParamMap(request);
List<DtaqLine> sections=dataLiveVideoManager.getLines(map);
JSONArray jsArry=new JSONArray();
JSONObject jsObj=new JSONObject();
for(DtaqLine obj:sections){
jsObj=new JSONObject();
jsObj.put("id",obj.getLine_id().toString());
jsObj.put("name",obj.getLine_name());
jsArry.add(jsObj);
}
super.renderText(response, jsArry.toString());
return null;
}
1页面直接先调用方法
例如 getLines('${param.qlineId}','${param.qsectionId}');////js部分
<select
id="qlineId" name="qlineId" onchange="getSections(this.value,'')"></select>
2,js方法的部分
//qlineId是当前选择的值 msg是后台传的字符串 type区分第几级的查询
第一级:function
getLines(qlineId,qsectionId){
$.post("dataLiveVideoAction.do?method=getLines",function(msg){
fillJsonNoSelect($("#qlineId"),msg,qlineId,1,qsectionId);
});
}
第二级:function
getSections(qlineId,qsectionId){
getWokPoints('','');
if(qlineId!=''){
$.post("dataLiveVideoAction.do?method=getSections&qlineId="+qlineId,function(msg){
fillJsonNoSelect($("#qsectionId"),msg,qsectionId,2);
});
}else{
fillJsonSelect($("#qsectionId"),"","");
}
}
第三级 function getWokPoints(qsectionId,qworkPointId){
getTypes('','');
if(qsectionId!=''){
$.post("dataLiveVideoAction.do?method=getWokPoints&qsectionId="+qsectionId,function(msg){
fillJsonNoSelect($("#qworkPointId"),msg,qworkPointId,3);
});
}else{
fillJsonSelect($("#qworkPointId"),"","");
}
}
//未做选择时赋予的请选择
function
fillJsonSelect(obj,jSonStr,setOb){
var selectObj = initSelect(obj,true) ;
if(jSonStr != null && jSonStr != ""){
var jSobj = JSON.parse(jSonStr);
var count=jSobj.length;
for(var i=0; i<count; i++){
var setStr="";
if(jSobj[i].id==$.trim(setOb)){
setStr="selected";
}
selectObj.append("<option value='"+jSobj[i].id+"' "+setStr+">"+jSobj[i].name+"</option>") ;
}
}
}
function
fillJsonNoSelect(obj,jSonStr,setOb,type,section){
var selectObj ;
if(jSonStr != null && jSonStr != ""){
var jSobj = JSON.parse(jSonStr);
var count=jSobj.length;
if(count==1){
selectObj = initSelect(obj,"false") ;//此方法是给定请选择
}else{
selectObj = initSelect(obj,true) ;
}
var seleteId='';
for(var i=0; i<count; i++){
var setStr="";
seleteId=jSobj[i].id;
if(jSobj[i].id==$.trim(setOb)){
setStr="selected"; ////默认标识
}
selectObj.append("<option value='"+jSobj[i].id+"' "+setStr+">"+jSobj[i].name+"</option>") ;
}
if(count==1){
if(type==1){
getSections(seleteId,section);
}else if(type==2){
//getWokPoints(seleteId,'');
}
}
}
}
function
initSelect(selectObj,showNull){
selectObj.find("option").remove();
selectObj.append("<option value=''>--请选择--</option>") ;
return selectObj ;
}