请高手帮忙看下,一个关于设置DIV层坐标的问题,谢谢了 这个POSITION还得设为 absolute; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title> 无标题文档 </title> <script type="text/javascript"> function cen(){ var f=document.getElementsByTagName("body").item(0); var divv=document.createElement("div"); var txt=document.createTextNode("Hello word!"); divv.appendChild(txt); divv.style.border="black 1px solid"; divv.style.backgroundColor="#00FF00"; divv.style.position = "absolute";divv.style.left=600+"px"; divv.style.top=170+"px"; divv.style.width=150+"px"; divv.style.height=150+"px"; f.appendChild(divv); } </script> </head> <body> <form id="form1" action=""> <input id="wolai" type="button" value="添加" onclick="cen()" /> </form> <div style="background-color: #000000;Z-INDEX: 1; LEFT: 300px; WIDTH: 110px; POSITION: absolute; TOP: 320px; HEIGHT: 196px; "></div></body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title> 无标题文档 </title> <script type="text/javascript"> function cen(){ var f=document.getElementsByTagName("body").item(0); var divv=document.createElement("div"); var txt=document.createTextNode("Hello word!"); divv.appendChild(txt); divv.style.border="black 1px solid"; divv.style.backgroundColor="#00FF00"; divv.style.position = "absolute";divv.style.left=600+"px"; divv.style.top=170+"px"; divv.style.width=150+"px"; divv.style.height=150+"px"; f.appendChild(divv); } </script> </head> <body> <form id="form1" action=""> <input id="wolai" type="button" value="添加" onclick="cen()" /> </form> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="roots" content="" /> <meta name="Keywords" content="" /> <meta name="Description" content="" /> <title>Demo</title> <link rel="stylesheet" rev="stylesheet" type="text/css" media="screen, projection" href="css/master.css" /> <script src="js/common.js" type="text/javascript" language="javascript" ></script> <script type="text/javascript" language="javascript"> <!-- /* Author: Kevin Xiao Email: [email protected] Web:www.bluekevin.com Msn:[email protected] */ function $(id) {return document.getElementById(id);} function $F(name){return document.getElementsByTagName(name);} var f=0; function show(obj,objCon){ document.getElementById('qq').style.visibility="hidden"; var obj=$(obj); if(!obj){return false;} var objCon=$(objCon) objCon.style.top=(obj.offsetTop+20)+'px'; objCon.style.left=(obj.offsetLeft+0)+'px'; objCon.style.position="absolute"; //objCon.style.zIndex="2"; /*var iframes=document.createElement('iframe'); iframes.style.top=(obj.offsetTop+0)+'px'; iframes.style.left=(obj.offsetLeft+0)+'px'; iframes.style.width=objCon.offsetWidth; iframes.style.height=objCon.offsetHeight; iframes.style.position="absolute"; iframes.style.zIndex="1"; // objCon.appendChild(iframes); document.body.appendChild(iframes);*/ if(objCon.style.display=='block'){ objCon.style.display='none'; document.getElementById('qq').style.visibility=""; //iframes.style.display='none'; }else objCon.style.display='block'; objCon.onmouseover=function(){f=0;} objCon.onmouseout=function(){f=1;}} function hide(obj,objCon){ var obj=$(obj); if(!obj){return false;} var objCon=$(objCon) if(f=='0'){ objCon.style.display='block'; }else f=1; objCon.style.display='none';document.getElementById('qq').style.visibility="hidden";} //--> </script> <style type="text/css"> body { padding:0;margin:0; color:#666; font:12px arial,sans-serif; } .menu ul {list-style:none;padding:0;margin:0;} .menu ul li {padding:0;margin:0;} .menu ul li a {background-color:#ddd;} .nav {height:30px;line-height:30px;border:0px solid red;} .nav ul{list-style:none;} .nav ul li{display:inline;} .nav ul li a{border:1px solid blue;margin:1px 20px} .loginCon{border:1px solid red;width:400px;margin-left:0px;margin-top:0px;background-color:#ddd;} .menu{border:1px solid red;} .loginCon dl ,loginCon dt ,loginCon dd {padding:0;margin:0;} .loginCon dl {width:350px;} .loginCon dt {width:70px;float:left;text-align:left;} .loginCon span{float:right;cursor:pointer;margin:5px} </style></head><body ><div class="nav"> <ul> <li><a id="m1" href="###" onclick="show('m1','login')">点击登录</a></li> </ul></div><div id="login" class="loginCon" style="display:none"> <span onclick="hide('m2','login')">关闭</span> <dl> <dt><label for="user">username:</label></dt> <dd><input type="text" id="user" value="11"/></dd> <dt><label for="pwd">password:</label></dt> <dd><input type="password" id="pwd" value="11"/></dd> <dt></dt> <dd><input type="button" id="submit" value="login"/> <input type="button" id="clear" value="clear"/></dd> </dl></iframe></div><select id="qq"> <option value="" selected="selected">11111111111111111</option> <option value="">22222222222222</option></select>BUGselect 不能显示在div下面</body></html>look 汗!他的代码只需要在JS中加一个divv.style.position = "absolute";就可以了还需要用你这么长的代码啊? 对,楼主,四楼的代码已经可以了,自己看看吧其实就是少了一句话,divv.style.position = "absolute"; 关于JS代码兼容360的问题 js弹出另一个页面中的某个DIV JS方法执行问题 frames与新窗口的问题 关于Extjs4 的RowExpander.js 怎么用?急急急急急急急急急 这段代码怎么实现调取id 设为首页 的代码问题 一个小问题,请看看.... javaScript和JScript的区别在什么地方? 谁帮我改好加分100 关于使用Javascript日历控件的问题,亲求帮助 求达人帮助一个正则表达式的写法
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> 无标题文档 </title>
<script type="text/javascript">
function cen(){
var f=document.getElementsByTagName("body").item(0);
var divv=document.createElement("div");
var txt=document.createTextNode("Hello word!");
divv.appendChild(txt);
divv.style.border="black 1px solid";
divv.style.backgroundColor="#00FF00";
divv.style.position = "absolute";
divv.style.left=600+"px";
divv.style.top=170+"px";
divv.style.width=150+"px";
divv.style.height=150+"px";
f.appendChild(divv);
}
</script>
</head> <body>
<form id="form1" action="">
<input id="wolai" type="button" value="添加" onclick="cen()" />
</form>
<div style="background-color: #000000;Z-INDEX: 1; LEFT: 300px; WIDTH: 110px; POSITION: absolute; TOP: 320px; HEIGHT: 196px; "></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> 无标题文档 </title>
<script type="text/javascript">
function cen(){
var f=document.getElementsByTagName("body").item(0);
var divv=document.createElement("div");
var txt=document.createTextNode("Hello word!");
divv.appendChild(txt);
divv.style.border="black 1px solid";
divv.style.backgroundColor="#00FF00";
divv.style.position = "absolute";
divv.style.left=600+"px";
divv.style.top=170+"px";
divv.style.width=150+"px";
divv.style.height=150+"px";
f.appendChild(divv);
}
</script>
</head> <body>
<form id="form1" action="">
<input id="wolai" type="button" value="添加" onclick="cen()" />
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="roots" content="" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<title>Demo</title>
<link rel="stylesheet" rev="stylesheet" type="text/css" media="screen, projection" href="css/master.css" />
<script src="js/common.js" type="text/javascript" language="javascript" ></script>
<script type="text/javascript" language="javascript">
<!--
/*
Author: Kevin Xiao
Email: [email protected]
Web:www.bluekevin.com
Msn:[email protected]
*/ function $(id) {return document.getElementById(id);}
function $F(name){return document.getElementsByTagName(name);}
var f=0;
function show(obj,objCon){
document.getElementById('qq').style.visibility="hidden";
var obj=$(obj);
if(!obj){return false;}
var objCon=$(objCon)
objCon.style.top=(obj.offsetTop+20)+'px';
objCon.style.left=(obj.offsetLeft+0)+'px';
objCon.style.position="absolute";
//objCon.style.zIndex="2"; /*var iframes=document.createElement('iframe');
iframes.style.top=(obj.offsetTop+0)+'px';
iframes.style.left=(obj.offsetLeft+0)+'px';
iframes.style.width=objCon.offsetWidth;
iframes.style.height=objCon.offsetHeight; iframes.style.position="absolute";
iframes.style.zIndex="1";
// objCon.appendChild(iframes);
document.body.appendChild(iframes);*/ if(objCon.style.display=='block'){
objCon.style.display='none';
document.getElementById('qq').style.visibility="";
//iframes.style.display='none';
}else objCon.style.display='block';
objCon.onmouseover=function(){f=0;}
objCon.onmouseout=function(){f=1;}
}
function hide(obj,objCon){
var obj=$(obj);
if(!obj){return false;}
var objCon=$(objCon)
if(f=='0'){
objCon.style.display='block';
}else f=1; objCon.style.display='none';document.getElementById('qq').style.visibility="hidden";
}
//-->
</script>
<style type="text/css"> body
{
padding:0;margin:0;
color:#666;
font:12px arial,sans-serif;
}
.menu ul {list-style:none;padding:0;margin:0;}
.menu ul li {padding:0;margin:0;}
.menu ul li a {background-color:#ddd;}
.nav {height:30px;line-height:30px;border:0px solid red;}
.nav ul{list-style:none;}
.nav ul li{display:inline;}
.nav ul li a{border:1px solid blue;margin:1px 20px}
.loginCon{border:1px solid red;width:400px;margin-left:0px;margin-top:0px;background-color:#ddd;}
.menu{border:1px solid red;}
.loginCon dl ,loginCon dt ,loginCon dd {padding:0;margin:0;}
.loginCon dl {width:350px;}
.loginCon dt {width:70px;float:left;text-align:left;}
.loginCon span{float:right;cursor:pointer;margin:5px}
</style>
</head><body >
<div class="nav">
<ul>
<li><a id="m1" href="###" onclick="show('m1','login')">点击登录</a></li>
</ul>
</div>
<div id="login" class="loginCon" style="display:none">
<span onclick="hide('m2','login')">关闭</span>
<dl>
<dt><label for="user">username:</label></dt>
<dd><input type="text" id="user" value="11"/></dd>
<dt><label for="pwd">password:</label></dt>
<dd><input type="password" id="pwd" value="11"/></dd>
<dt></dt>
<dd><input type="button" id="submit" value="login"/> <input type="button" id="clear" value="clear"/></dd>
</dl>
</iframe>
</div>
<select id="qq">
<option value="" selected="selected">11111111111111111</option>
<option value="">22222222222222</option>
</select>BUG
select 不能显示在div下面
</body></html>look
就可以了
还需要用你这么长的代码啊?