js类代码:
/*************************************
*
* Class:ContractTypeListboxOne
* 2011-5-18 20:08:00
**************************************/
//-- 构造函数
function TypeListbox(id,parentId,nextId,nextParentId){
this.id=id;
this.parentId=parentId;
this.nextId=nextId;
this.nextParentId=nextParentId;
this.init();
this.fillData($(this.id),parentId);
}

//-- 初始化
TypeListbox.prototype.init=function(){
var ctrl=$(this.id);
var me=this;
ctrl.onchange=function(){
me.changeEvent();
}
}

//-- 变化事件
TypeListbox.prototype.changeEvent=function(){
var ctrl=$(this.id);
if(this.nextId.length>0 && this.nextId!="none"){
this.fillData($(this.nextId),ctrl.value);
}
}

//-- 填充数据
TypeListbox.prototype.fillData=function(myListbox,parentId){
/*if(parentId.length<1 || parentId=="none"){
return;
}*/

var url=encodeURI('GetContractType.do?parentId='+parentId);
url=encodeURI(url);
new Ajax.Request(url,{
method:'get',
onSuccess: function(ajaxObj){
// alert(ajaxObj.responseText);
var status=ajaxObj.responseXML.getElementsByTagName("status")[0].firstChild.data;
if(status=="ok"){
// 返回正确信息

// 找到所有节点放入数组,为避免麻烦,节点名统一都设置成node比较好,不用实例变了,这里就要改变一次。
var arr=ajaxObj.responseXML.getElementsByTagName("node");
var length=arr.length;

for(var i=myListbox.options.length-1;i>=0;i--){
myListbox.remove(i);
}
var newOption=new Option;
newOption.value="";
newOption.text="--请选择--";
myListbox.add(newOption);

if(length>0){
// 遍历这个数组
for(var i=0;i<length;i++){
var node=arr[i];
var id=node.getElementsByTagName("id")[0].firstChild.data;
var name=node.getElementsByTagName("name")[0].firstChild.data;
var newOption=new Option;
newOption.value=id;
newOption.text=name;
myListbox.add(newOption);
}
}
myListbox.selectedIndex=0;
myListbox.fireEvent("onchange");
}
else{
// 返回错误信息
var text=ajaxObj.responseXML.getElementsByTagName("text")[0].firstChild.data;
alert(text);
}
},
onFailure: function(){
alert("无法取得服务器的响应");
}
}
);
}页面下拉列表框:
< tr>
<td width="100%" colspan="10">
<div class="inputText">
<label for="classOneCbo">合同类别:</label>
<select id="classOneCbo">
<option value="" selected>--请选择--</option>
</select>
<font color="#003366">-</font>
<select id="classTwoCbo">
<option value="" selected>--请选择--</option>
</select>
<font color="#003366">-</font>
<select id="classThreeCbo">
<option value="" selected>--请选择--</option>
</select>
</div>
</td>
</tr>页面JS初始化代码:
/*****************************************************
* 窗口载入时调用的启动函数
* 何杨,2011年4月22日16:59:16
*****************************************************/
window.onload= function(){
// 设置主菜单的当前菜单项
setMainmenuCurrentItem(0);
// 设置侧边菜单的当前菜单项
setSidemenuCurrentItemByText("待办事项");
// 填充下拉列表框数据
new TypeListbox("classOneCbo","0","classTwoCbo","");
new TypeListbox("classTwoCbo",$("classOneCbo").value,"classThreeCbo","");
// 开始检索初始数据
search(0);
}
|