简体   繁体   English

如何仅使用javascript制作固定的div框(无CSS,jQuery,HTML)

[英]How to make a fixed div box using javascript ONLY (no css, jquery, html)

I've been searching for a way to do this all day but have had no luck. 我一直在寻找一种方法来整天这样做,但没有运气。 My apologies if I missed a post about this somehow. 如果我错过关于此的帖子,我深表歉意。 I'm working with Qualtrics currently and am trying to code to have a textbox with the instructions scrolling down the page with the participant as they fill out the survey. 我目前正在与Qualtrics合作,并且正在尝试编写一个文本框,其中的说明会在参与者填写调查表时向下滚动说明。 I have never worked with javascript coding before today, I am only familiar with basic html. 今天以前,我从未使用过JavaScript编码,只熟悉基本的html。 From what I have found today I believe I need to code for a fixed div box. 从今天的发现中,我相信我需要为一个固定的div框编码。 I did find codes, but they all had elements of html or css involved, which the qualtrics program does not allow for. 我确实找到了代码,但是它们都包含html或css元素,而qualtrics程序不允许这样做。 In qualtrics you must code within the question itself. 在定性中,您必须在问题本身内进行编码。 Is there anyway I can code for this using only javascript? 无论如何,我只能使用javascript进行编码吗? Thank you so much in advance! 提前非常感谢您!

Do you mean something like this? 你的意思是这样吗?

var box = document.createElement('div');
box.style.position = 'fixed';
box.style.top = '100px';
box.style.right = '10px';
box.style.width = '200px';
box.style.height = '100px';
box.style.color = 'black';
box.style.background = 'lightblue';
box.style.padding = '20px';
box.innerText = 'Hello world';
document.body.appendChild(box);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM