在input前插入内容

方法一:


var objDiv = document.createElement('DIV'); 
var txt = document.getElementById("txt1");
txt.parentNode.insertBefore(objDiv,txt);



方法二:


function getAbsoluteTop(obj){
var top = obj.offsetTop;
while(obj != null && obj.offsetParent != null && obj.offsetParent.tagName != 'BODY'){
top += obj.offsetParent.offsetTop;
obj = obj.offsetParent;
}
return top;
}
function getAbsoluteLeft(obj){
var left = obj.offsetLeft;
while(obj != null && obj.offsetParent != null && obj.offsetParent.tagName != 'BODY'){
left += obj.offsetParent.offsetLeft;
obj = obj.offsetParent;
}
return left;
}
function getAbsoluteWidth(obj){
return obj.offsetWidth;
}
function getAbsoluteHeight(obj){
return obj.offsetHeight;
}
//objDoc是对于那个var objDoc = document.getElementById("txt1"); 
function divPosition(objDoc){
objDiv.style.left = getAbsoluteLeft(objDoc);
objDiv.style.top = getAbsoluteTop(objDoc)+getAbsoluteHeight(objDoc);
objDiv.style.width = getAbsoluteWidth(objDoc);
}

你可能感兴趣的:(input)