拖曳选取复选框

None.gif < html >
None.gif
< SCRIPT language = JavaScript >
None.gifvar x0;
None.gifvar y0;
None.gifvar selectenable
= 0 ;
None.gif
None.gif
function  initChkBox(obj){
None.gifvar coll
= document.forms[ " form1 " ].tags( " input " );
None.gif    
for  (i = 0 ;i < coll.length;i ++ ){
None.gif     
if  (coll.item(i).name.substr( 0 , 2 ) == " ck " ) {
None.gif   var offsetTop 
=   0 ;
None.gif   var offsetLeft 
=   0 ;
None.gif   var objP 
=  coll.item(i);
None.gif   
while  (objP.tagName! = " BODY " && objP){
None.gif    offsetTop 
+=  objP.offsetTop;
None.gif    offsetLeft 
+=  objP.offsetLeft;
None.gif    objP 
=  objP.offsetParent;
None.gif   }
None.gif   coll.item(i).X
= offsetLeft + 10 ;
None.gif   coll.item(i).Y
= offsetTop + 10 ;
None.gif   
// alert(coll.item(i).X + " , " + coll.item(i).Y + " , " + coll.item(i).offsetHeight);
None.gif  }
None.gif }
None.gif}
None.gif
None.gif
function  initselect() {
None.gif       
if  (window.event.srcElement.tagName == " BODY " ) {
None.gif        window.event.returnValue 
=   true ;
None.gif        return;
None.gif       }
None.gif    
None.gif        x0
= document.body.scrollLeft + event.clientX;
None.gif     y0
= document.body.scrollTop + event.clientY;
None.gif  selectarea.setCapture();
None.gif     selectenable
= 1 ;
None.gif}
None.gif
function  startselect() {
None.gif    
if  (selectenable == 1 ) {
None.gif        selectarea.style.visibility
= ' visible';
None.gif
  
None.gif        
if (document.body.scrollLeft + event.clientX - x0 > 0 ) {
None.gif      selectarea.style.left
= x0;
None.gif      selectarea.style.width
= document.body.scrollLeft + event.clientX - x0;
None.gif    }
None.gif        
else {
None.gif      selectarea.style.left
= document.body.scrollLeft + event.clientX;
None.gif      selectarea.style.width
= x0 - (document.body.scrollLeft + event.clientX);
None.gif     }
None.gif        
if  (document.body.scrollTop + event.clientY - y0 > 0 ) {
None.gif     selectarea.style.top
= y0; 
None.gif     selectarea.style.height
= document.body.scrollTop + event.clientY - y0;
None.gif     }
None.gif       
else {
None.gif     selectarea.style.top
= document.body.scrollTop + event.clientY;
None.gif     selectarea.style.height
= y0 - (document.body.scrollTop + event.clientY);
None.gif     }
None.gif }
None.gif    window.event.returnValue 
=   true ;
None.gif}
None.gif
None.gif
function  endselect() {
None.gif 
if  (selectenable == 0 ) return  false ;
None.gif    selectenable
= 0 ;
None.gif selectarea.style.visibility
= ' hidden';
None.gif
 selectarea.releaseCapture(); 
None.gif document.onmousemove
= null ;
None.gif var coll
= document.forms[ " form1 " ].tags( " input " );
None.gif    
for  (i = 0 ;i < coll.length;i ++ ){
None.gif     
if  (coll.item(i).name.substr( 0 , 2 ) == " ck " ) {
None.gif   
if  (coll.item(i).X > selectarea.offsetLeft)
None.gif    
if  (coll.item(i).X < selectarea.offsetLeft + selectarea.offsetWidth)  
None.gif     
if  (coll.item(i).Y > selectarea.offsetTop)
None.gif      
if  (coll.item(i).Y < selectarea.offsetTop + selectarea.offsetHeight)
None.gif       coll.item(i).checked
= !coll.item(i).checked
None.gif  }
None.gif } 
None.gif selectarea.style.pixelHeight
= 0 ;
None.gif selectarea.style.pixelWidth
= 0 ;
None.gif}
None.gif
function  checkAll(){
None.gif  document.form1.allsel.checked
= false ;
None.gif  var coll
= document.forms[ " form1 " ].tags( " input " );
None.gif    
for  (i = 0 ;i < coll.length;i ++ ){
None.gif     
if  (coll.item(i).name.substr( 0 , 2 ) == " ck " ) {
None.gif       coll.item(i).checked
= false ;
None.gif   }
None.gif  }
None.gif}
None.gif
function  change(v){
None.gif  var f 
=  document.forms[ " form1 " ];
None.gif  
for  (i = 0 ;i < f.elements.length;i ++ )
None.gif    
if  (f.elements[i].name.substr( 0 , 2 ) == " ck " ) f.elements[i].checked  =  v;
None.gif
None.gif
SCRIPT >
None.gif
< body onmousedown = " initselect() "  onmousemove = startselect() onmouseup = endselect() onselectstart = " return false; "  onLoad = initChkBox() >
None.gif
< table width = " 100% "  height = " 100% "  cellpadding = " 0 "  cellspacing = " 0 " >
None.gif
< tr >< td >
None.gif  
< DIV id = selectarea style = " border:1px dashed black;HEIGHT: 42px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; WIDTH: 67px; Z-INDEX: 10 " >  
None.gif    
< img src = " null "  height = " 1 "  width = " 1 " >   DIV >
None.gif  
< div id = " Layer1 "  style = " position:absolute; left:56px; top:39px; width:203px; height:401px; z-index:1 " >  
None.gif    
< form name = " form1 "  action = "" >
None.gif      
< table width = " 100% "  border = " 0 "  cellpadding = " 0 "  cellspacing = " 1 "  bgcolor = " #339999 " >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td width = " 13% " >< input type = " checkbox "  name = " ck1 "  value = " checkbox " > td >
None.gif          
< td width = " 87% " >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck2 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck3 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck4 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck5 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck6 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck7 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck8 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck9 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck10 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck11 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck12 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck13 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck14 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck15 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif        
< tr bgcolor = " #FFFFFF " >  
None.gif          
< td >< input type = " checkbox "  name = " ck16 "  value = " checkbox " > td >
None.gif          
< td >& nbsp; td >
None.gif        
tr >
None.gif      
table >
None.gif      
< input type = " checkbox "  name = " allsel "  value = " checkbox "  onclick = " change(this.checked) " >
None.gif      
< button onClick = " checkAll() " > 清空 button >
None.gif    
form >
None.gif  
div >
None.gif
td > tr >   
None.gif
table >
None.gif
body >
None.gif
html >
None.gif
None.gif

转载于:https://www.cnblogs.com/jinchun/archive/2007/02/03/638700.html

你可能感兴趣的:(javascript)