弹出可移动的编辑框

阅读更多
[size=small]/**
* 显示输入框内容并编辑
*/
[size=large][size=x-small]function editFieldVal(obj){
var isReadOnly = obj.isReadOnly;//控件是否可以编辑
var read = obj.className;
var text = obj.value;
var editDiv = document.getElementById("editDiv");
if(null!=editDiv)
return false;
var div= document.createElement("div");
div.style.position="relative";
div.style.left="400px";
div.style.width="400px";
div.style.height="300";
div.style.top="140px";
div.style.zIndex ="2000";
div.style.border="3px solid #b2ccb8";
div.style.backgroundColor="#e4ebe5";
div.setAttribute("id","editDiv");
var ta = document.createElement("textarea");
var text = text.replace(/。/g,'。'+'\r\n');
ta.value=text;
ta.style.margin="15px 15px 15px 15px";
ta.style.top="10px";
ta.style.paddingTop="5px";
ta.style.paddingLeft="5px";
ta.style.paddingRight="5px";
ta.style.fontSize="14";
ta.style.width="385px";
ta.style.height="260px";
div.appendChild(ta);
var save = document.createElement("button");
save.value="确定";
save.style.width="65px";
save.style.height="26px";
save.style.backgroundColor="#aec5e9";
save.style.marginLeft="37%";
save.style.marginTop="2%";
save.style.marginBottom="10px";
save.onclick= function(){
var taval = ta.value.replace(/\r\n/g,'。');
taval = taval.replace(/[。]+/g,'。');
//特别约定这样处理
if(obj.name.indexOf("FixSpec.CSpecContent")!=-1){
tool.setAttrValue(dw['FixSpec'],"FixSpec.CSpecContent",taval);
sumFix();
}else{
obj.value = taval;
}
document.body.removeChild(div);
};
if(!isReadOnly){
save.disabled="disabled";
}
if(read=='read' || read == "readtextarea1"){
save.disabled="disabled";
ta.disabled="disabled";
}
div.appendChild(save);
rDrag.init(div);
var cancle = document.createElement("button");
cancle.value="取消";
cancle.style.width="65px";
cancle.style.height="26px";
cancle.style.backgroundColor="#aec5e9";
cancle.style.marginLeft="5%";
cancle.style.marginTop="2%";
cancle.style.marginBottom="10px";
cancle.onclick= function(){
document.body.removeChild(div);
};
div.appendChild(cancle);
document.body.appendChild(div);
}
[/size]

/**
*悬浮框移动
*
*/
[size=large]var rDrag = {
o : null,
init : function(o) {
o.onmousedown = this.start;
},
start : function(e) {
var o;
e = rDrag.fixEvent(e);
e.preventDefault && e.preventDefault();
rDrag.o = o = this;
o.x = e.clientX - rDrag.o.offsetLeft;
o.y = e.clientY - rDrag.o.offsetTop;
document.onmousemove = rDrag.move;
document.onmouseup = rDrag.end;
},
move : function(e) {
e = rDrag.fixEvent(e);
var oLeft, oTop;
oLeft = e.clientX - rDrag.o.x;
oTop = e.clientY - rDrag.o.y;
rDrag.o.style.left = oLeft + 'px';
rDrag.o.style.top = oTop + 'px';
},
end : function(e) {
e = rDrag.fixEvent(e);
rDrag.o = document.onmousemove = document.onmouseup = null;
},
fixEvent : function(e) {
if (!e) {
e = window.event;
e.target = e.srcElement;
e.layerX = e.offsetX;
e.layerY = e.offsetY;
}
return e;
}
}

你可能感兴趣的:(JS)