javascript实现鼠标选取拖动或Ctrl选取拖动
*{position:absolute;}
#panel *{border:1px solid gray}
/**********判断浏览器**********/
var isIE = false;
if(document.all) isIE = true;
/*******HashArray*******/
function HashArray(){
this.keyList = new Array();
this.put = function(key, value){
this[key] = value;
if(!this.containsKey(key)){
this.keyList.push(key);
}
}
this.size = function(){
return this.keyList.length;
}
this.containsKey = function(key){
if(this.keyList.length == 0) return false;
var keyStr = this.keyList.join(",") + ",";
if(keyStr.indexOf(key + ",") == -1){
return false;
}else{
return true;
}
}
this.get = function(key){
return this[key];
}
this.keySet = function(){
return this.keyList;
}
this.isEmpty = function(){
return this.keyList.length==0;
}
this.remove = function(key){
if(this.containsKey(key)){
delete this[key];
this.keyList.splice(this.getIndex(key), 1);
}
}
this.removeAll = function(key){
for(var i=0;i originX){
divMove.style.left = originX+ "px";
}else divMove.style.left = (x-2)+ "px";
if(y > originY){
divMove.style.top = originY+ "px";
}else divMove.style.top = (y-2)+ "px";
}
}
/**********处理mousedown事件********/
function mousedown(e){
if(isIE){
if(event.srcElement.id == "panel"){
originX=event.x;
originY=event.y;
isMouseDown=true;
}else{
isDrag = true;
}
}else{
if(e.target.id == "panel"){
originX=e.pageX;
originY=e.pageY;
isMouseDown=true;
}else{
isDrag = true;
}
}
}
/**********处理mouseup事件********/
function mouseup(e){
if(isIE){
if(event.srcElement.id == "divMove" || event.srcElement.id == "panel"){
selectObjects();
isMouseDown=false;
divMove.style.display='none';
}else{
if(DragObject.curObj) DragObject.curObj.endDrag();
isDrag = false;
}
}else{
if(e.target.id == "divMove" || e.target.id == "panel"){
selectObjects();
isMouseDown=false;
divMove.style.display='none';
}else{
if(DragObject.curObj) DragObject.curObj.endDrag();
isDrag = false;
}
}
}
/*********选中对象********/
function selectObjects(){
for(var i=0;i divMove.offsetLeft && objX divMove.offsetTop && objY
中国是一个发展中国家
var divMove = $("divMove");
var elems = $("panel").children;
document.onmousemove=moveDiv;
document.onmousedown=mousedown;
document.onmouseup=mouseup;
for(var i=0;i
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]