js的两个小应用

1、在客户端对两个ListBox中的项进行交互选择;

2、对GridView中的复选框进行全选操作。

 

1、

function AddItem(lstFrom,lstTo) 
{    
    
var lstFrom = document.getElementById(lstFrom);
    
var lstTo = document.getElementById(lstTo);
    
var j=lstFrom.selectedIndex;    
    
var i;  
    
var optItem,oOption;
    
var szItemText;    
    
var blstToResist;                
    
for (i = lstFrom.length - 1;i >= 0;i--)
    
{
    
if (lstFrom.item(i).selected==true)
    
{
                oOption 
= window.document.createElement("OPTION");
        optItem 
= lstFrom(i);
        szItemText 
= optItem.text;
        oOption.text
=optItem.text;
        oOption.value
=optItem.value;
        oOption.className
="SltOption";
        blstToResist
=CheckInList("text",szItemText,lstTo); 
        
if (blstToResist==false)
        
{                               
                lstTo.add(oOption);        
        }
                    
        lstFrom.remove(i);
    }

    }

}

function CheckInList(optAtr, szCompare, lst)
{
    
var i;    
    
for(i=0;i<lst.length ;i++)
    
{
        
if (lst.item(i).getAttribute(optAtr)==szCompare)
        
return true;
    }
    
    
return false;
}

 

2、

 

function CheckAll(oCheckbox)
 
{
       
var GridView2 = document.getElementById("<%=GridView2.ClientID %>");
       
for(i = 1;i < GridView.rows.length; i++)
       
{        GridView.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
     }

  }

 

后台的C#进行全选的代码也贴出来晒晒:

 

Code

 

 

posted @ 2008-07-30 11:56  JerryShi  阅读(268)  评论(0编辑  收藏  举报