Chinaunix首页 | 论坛 | 博客
  • 博客访问: 35517
  • 博文数量: 16
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 105
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-09 09:59
文章分类

全部博文(16)

文章存档

2010年(16)

我的朋友

分类: 系统运维

2010-08-03 14:19:12

一基础理解:

var e = document.getElementById("selectId");

e. options= new Option("文本","值") ;

//创建一个option对象,即在
    
    
    
    

click="number();">






根据这些东西,自己用JQEURY AJAX+JSON实现了一个小功能如下:

JS代码:(只取了于SELECT相关的代码)
/**
   * @description 构件联动下拉列表 (用JQUERY 的AJAX配合JSON实现)
   * @prarm selectId 下拉列表的ID
   * @prarm method 要调用的方法名称
   * @prarm temp 此处存放软件ID
   * @prarm url 要跳转的地址
   */
function linkAgeJson(selectId,method,temp,url){   
      $j.ajax({    
            type: "get",//使用get方法访问后台
            dataType: "json",//返回json格式的数据
            url: url,//要访问的后台地址
            data: "method=" + method+"&temp="+temp,//要发送的数据        
            success: function(msg){//msg为返回的数据,在这里做数据绑定
                var data = msg.lists;
                coverJsonToHtml(selectId,data);             
            }
        });
}

/**
* @description 将JSON数据转换成HTML数据格式
* @prarm selectId 下拉列表的ID
* @prarm nodeArray 返回的JSON数组
*
*/
function coverJsonToHtml(selectId,nodeArray){
//get select
   var tempSelect=$j("#"+selectId);
   //clear select value
   isClearSelect(selectId,'0');   
var tempOption=null;
for(var i=0;i //create select Option
tempOption= $j(' ');
//put Option to select
tempSelect.append(tempOption);
        }
        // 获取退化构件列表
       getCpgjThgl(selectId,'thgjDm');
   }
   /**
   * @description 清空下拉列表的值
   * @prarm selectId 下拉列表的ID
   * @prarm index 开始清空的下标位置
   */
function isClearSelect(selectId,index){
     var length=document.getElementById(selectId).options.length;
while(length!=index){
      //长度是在变化的,因为必须重新获取
          length=document.getElementById(selectId).options.length;
          for(var i=index;i              document.getElementById(selectId).options.remove(i);
         length=length/2;
     }
   }
     
/**
* @description 获取退化构件列表
* @prarm selectId1 引用软件下拉列表的ID
* @prarm selectId2 退化构件下拉列表的ID
*/
   function getCpgjThgl(selectId1,selectId2){
   var obj1=document.getElementById(selectId1);//引用软件下拉列表
   var obj2=document.getElementById(selectId2);//退化构件下拉列表
   var len=obj1.options.length;
//当引用软件列表长度等于1时返回,不做操作
   if(len==1){
          return false;
   }
   //清空下拉列表的值,两种方式都可以
// isClearSelect(selectId2,'1');
            document.getElementById(selectId2).length=1;
   for(var i=0;i var option= obj1.options[i];
//引用软件被选中项不加入
if(i!=obj1.selectedIndex){
//克隆OPTION并添加到SELECT中  
obj2.appendChild(option.cloneNode(true));
}
}

   }




HTML代码:














*引用软件:


onClick="linkAgeTree('linkage','yyrjtree','yyrjMc','yyrjDm','linkageTree','1');" value="选择...">
*引用分版:

退化构件:
  
阅读(685) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~