可以把父容器设置为relative、新添加的元素为absolute。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script> function abc() { var text1=document.getElementById("text1"); var button=document.createElement("input"); button.setAttribute("type","button"); button.setAttribute("value",text1.value); button.style.cssText="position:absolute;left:0;top:0"; var div1=document.getElementById("div1"); div1.appendChild(button); }
马N甲N号 的时候:
<span class="最外面的span"><span class="标签"><input value=马N甲N号/></span><input/></span>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>
function abc()
{
var text1=document.getElementById("text1");
var button=document.createElement("input");
button.setAttribute("type","button");
button.setAttribute("value",text1.value);
button.style.cssText="position:absolute;left:0;top:0";
var div1=document.getElementById("div1");
div1.appendChild(button);
}
</script>
<body>
<div id="div1" style="position:relative">
<input type="text" id="text1" />
<input type="button" value="确定" onclick="abc()"/>
</div>
</body>
</html>