js類代碼:
/*************************************
*
* Class:ContractTypeListboxOne
* 2011-5-18 20:08:00
**************************************/
//-- 構(gòu)造函數(shù)
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);
}
}

//-- 填充數(shù)據(jù)
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"){
// 返回正確信息

// 找到所有節(jié)點(diǎn)放入數(shù)組,為避免麻煩,節(jié)點(diǎn)名統(tǒng)一都設(shè)置成node比較好,不用實(shí)例變了,這里就要改變一次。
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){
// 遍歷這個數(shù)組
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("無法取得服務(wù)器的響應(yīng)");
}
}
);
}頁面下拉列表框:
< 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初始化代碼:
/*****************************************************
* 窗口載入時調(diào)用的啟動函數(shù)
* 何楊,2011年4月22日16:59:16
*****************************************************/
window.onload= function(){
// 設(shè)置主菜單的當(dāng)前菜單項(xiàng)
setMainmenuCurrentItem(0);
// 設(shè)置側(cè)邊菜單的當(dāng)前菜單項(xiàng)
setSidemenuCurrentItemByText("待辦事項(xiàng)");
// 填充下拉列表框數(shù)據(jù)
new TypeListbox("classOneCbo","0","classTwoCbo","");
new TypeListbox("classTwoCbo",$("classOneCbo").value,"classThreeCbo","");
// 開始檢索初始數(shù)據(jù)
search(0);
}
|