有没有一种方法可以定位 InnerHTML,使其位于正常范围内 html
Is there a way to position InnerHTML so it comes under something within the normal html
我有一个关于 innerHTML 定位的问题。我有一个表单,它也有一个使用 innerHTML 显示的计时器倒计时。问题是它目前在我的表格上方,最终导致一些我不打算解释的问题,我想将它放在表格下方。我知道我可以声明距离页面的底部、顶部、左侧、右侧等有多远,但是我不这样做,因为这需要一个绝对位置,而我不希望它是绝对的,但仍然坐在我的表格下面。这是当前位于顶部的包含它的代码:
<div id="checking"></div>
<script type="text/javascript">(5,"checking");</script>
</head>
<body bgcolor="yellow">
<div id=main>
<br><br>
<form method="POST" id="quizzes" action="">
<label for="question"><?php echo ($currentQuestion+1).". ". $questionsAndAnwsers[$currentQuestion]["question"];
?></label>
<input type="hidden" name="currentQuestion" value="<?php echo $currentQuestion;?>"><br>
<input type="text" name="guess" value="" placeholder="Answer...">
<input type="submit" name="btnsubmit" value="Next Question">
</form>
</div>
<script type="text/javascript">
seconds = 15;
runningtime = setInterval(function () {
var element = document.getElementById("checking");
element.innerHTML = "<h2 style='text-align:center'> <b>"+seconds+"</b> seconds</h2>";
if(seconds < 1){
clearInterval(runningtime);
document.getElementById('quizzes').submit();
}
seconds--;
}, 1000)
</script>
</body>
当您设置 <div>
的 innerHTML
时,它会将内容 放入 div.
如果您不想将它放在文档的顶部,不要将 <div>
放在文档的顶部。
移动源代码中的<div>
。
我有一个关于 innerHTML 定位的问题。我有一个表单,它也有一个使用 innerHTML 显示的计时器倒计时。问题是它目前在我的表格上方,最终导致一些我不打算解释的问题,我想将它放在表格下方。我知道我可以声明距离页面的底部、顶部、左侧、右侧等有多远,但是我不这样做,因为这需要一个绝对位置,而我不希望它是绝对的,但仍然坐在我的表格下面。这是当前位于顶部的包含它的代码:
<div id="checking"></div>
<script type="text/javascript">(5,"checking");</script>
</head>
<body bgcolor="yellow">
<div id=main>
<br><br>
<form method="POST" id="quizzes" action="">
<label for="question"><?php echo ($currentQuestion+1).". ". $questionsAndAnwsers[$currentQuestion]["question"];
?></label>
<input type="hidden" name="currentQuestion" value="<?php echo $currentQuestion;?>"><br>
<input type="text" name="guess" value="" placeholder="Answer...">
<input type="submit" name="btnsubmit" value="Next Question">
</form>
</div>
<script type="text/javascript">
seconds = 15;
runningtime = setInterval(function () {
var element = document.getElementById("checking");
element.innerHTML = "<h2 style='text-align:center'> <b>"+seconds+"</b> seconds</h2>";
if(seconds < 1){
clearInterval(runningtime);
document.getElementById('quizzes').submit();
}
seconds--;
}, 1000)
</script>
</body>
当您设置 <div>
的 innerHTML
时,它会将内容 放入 div.
如果您不想将它放在文档的顶部,不要将 <div>
放在文档的顶部。
移动源代码中的<div>
。