function Element(){
this.id;
this.name;
this.value;
this.style;
this.pX;
this.pY;
this.pW;
this.pH;
this.type;
this.elementContent;
this.create = function(){
if(this.type=="div"){
this.elementContent = "<div id='"+this.id+"' name='"+this.name+"' style='"+this.style+"'/>";
return this.elementContent;
}else if(this.type=="button"){
this.elementContent = "<input type='button' id='"+this.id+"' name='"+this.name+"' style='"+this.style+"' value='"+this.value+"' onMouseDown='down(this);' onMouseMove='moving(this,"+getPxValue(this.pX)+","+getPxValue(this.pY)+","+getPxValue(this.pW)+","+getPxValue(this.pH)+");' onMouseUp='up(this);'/>";
return this.elementContent;
}else if(this.type="text"){
this.elementContent = "<input type='text' id='"+this.id+"' name='"+this.name+"' style='"+this.style+"' value='"+this.value+"' onMouseDown='down(this);' onMouseMove='moving(this,"+getPxValue(this.pX)+","+getPxValue(this.pY)+","+getPxValue(this.pW)+","+getPxValue(this.pH)+");' onMouseUp='up(this);'/>";
return this.elementContent;
}
}
}
function DragObj() {
var flag=0;//0:no,1:yes
var x=0;
var y=0;
}
var dEvt = new DragObj();
function down(obj) {
//拖拽开始
dEvt.flag = 1;
//记录点击时鼠标坐标
dEvt.x = event.x;
dEvt.y = event.y;
obj.setCapture(); //得到鼠标
}
function moving(obj,pX,pY,pW,pH) {
if(event.button==1) {
if (dEvt.flag==1) {
//更新控件位置:新位置=鼠标位置-控件宽(高)/2
var left = event.x-pX-obj.style.pixelWidth/2;
var top = event.y-pY-obj.style.pixelHeight/2;
var width = getPxValue(obj.style.width);
var height = getPxValue(obj.style.height);
if(left>=0&&(parseInt(left)+parseInt(width))<=(parseInt(pW))){
obj.style.left = left;
}
if(top>=0&&(parseInt(top)+parseInt(height))<=(parseInt(pH))){
obj.style.top = top;
}
}
}
}
function up(obj) {
dEvt.flag=0;
obj.releaseCapture();
}
function getPxValue(px){
var str = px.substring(0,px.length-2);
return str;
}