Javascript Bgcolor在while循环中不工作
虽然我知道Javascript Bgcolor在while循环中不工作,javascript,html,web,background-color,Javascript,Html,Web,Background Color,虽然我知道bgcolor不是动态更改网页颜色的最佳方法,但是CSS路径似乎不允许像bgcolor那样的数字(除非我弄错了)。我的代码如下: <!DOCTYPE html> <html> <head> <title>Title</title> <script> while(1===1){ confirm("You will click this";) docume
bgcolor
不是动态更改网页颜色的最佳方法,但是CSS路径似乎不允许像bgcolor
那样的数字(除非我弄错了)。我的代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script>
while(1===1){
confirm("You will click this";)
document.write("<h1>HELLO</h1>");
document.bgcolor = bgcolor;
}
</script>
</head>
<body></body>
</html>
标题
而(1==1){
确认(“您将单击此按钮”)
写下“你好”;
document.bgcolor=bgcolor;
}
我也知道我的代码是无限循环的。你能试试document.body.style.background而不是document.bgcolor吗
还有,我不得不问,为什么需要无限循环呢?你可以查看一下以供参考 上面写着: document.bgColor在DOM级别2 HTML中不推荐使用。推荐的 另一种选择是使用CSS样式的背景色,可以 使用document.body.style.backgroundColor通过DOM访问。 另一种选择是document.body.bgColor,尽管这也是 HTML4.01中已弃用,支持CSS替代方案 所以,若你们去控制台,这样写,颜色会改变
document.body.style.backgroundColor = "darkblue"
与其他人所说的一样,第7行似乎出现了语法错误,这可能会给您带来问题;分号应该在括号后面。需要无限循环的具体原因是什么?另外,您在哪里定义了
bgcolor
?