[英]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.