[英]how to prevent javascript div popup from jumping back to the top of the page?
[英]how to generate a div on the top of the page from javascript after the page is loaded?
我正在尝试从小书签在屏幕一角生成一个 div 元素。
我试过了
var newdiv = document.createElement('div');
newdiv.id="blabal";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.style.width=300;
newdiv.style.heigth=200;
newdiv.style.position="fixed";
newdiv.style.top="20";
document.body.appendChild(newdiv);
现在可以使用。
谢谢。
您需要为px
提供值,并且在heigth
中有一个错字:
var newdiv = document.createElement('div');
newdiv.id="blabal";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.style.width="300px";
newdiv.style.height="200px";
newdiv.style.position="fixed";
newdiv.style.top="20px";
document.body.appendChild(newdiv);
这大部分是准确的,但是您的height
有误,您需要提供width
、 height
和top
的单位。 我假设像素,但解释器不会那么好; 200
可以是 em、像素、点、百分比(分别为200em
、 200px
、 200pt
和200%
):
var newdiv = document.createElement('div');
newdiv.id="blabal";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.style.width="300px";
newdiv.style.height="200px";
newdiv.style.position="fixed";
newdiv.style.top="20px";
document.body.appendChild(newdiv);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.