我在页面上有3个按钮;一个人做了一个舒缓的颜色变化,在闪烁的颜色变化,并应该重置页面。但是,重置页面按钮不在中心。请帮忙:这是我的代码:
<html>
<head>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
function iwarnedyou(){
intrvl=0;
for(nTimes=0;nTimes<9999;nTimes++){
intrvl += 1500;
setTimeout("document.bgColor='#8CD19D';",intrvl);
intrvl += 1500;
setTimeout("document.bgColor='#ACDEB2';",intrvl);
intrvl += 1500;
setTimeout("document.bgColor='#BFD8AD';",intrvl);
}
}
</SCRIPT>
<center>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Soooothe." onClick="iwarnedyou()">
</FORM>
</center>
<br/><div style="clear:both"></div><div><a target="_blank" href="Georgeocodes.github.io/"><span style="font-size: 8pt; text-decoration: none">George O Codes</span></a></div>
</body>
<body>
<SCRIPT LANGUAGE="JavaScript">
function iwarnedu(){
intrvl=0;
for(nTimes=0;nTimes<9999;nTimes++){
intrvl += 100;
setTimeout("document.bgColor='#FFFFFF';",intrvl);
intrvl += 100;
setTimeout("document.bgColor='#000000';",intrvl);
}
}
</SCRIPT>
<center>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Nightmare. [Warning: Flashing]" onClick="iwarnedu()">
</FORM>
</center>
<FORM>
<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh">
</FORM>
</body>
</html>
答案 0 :(得分:2)
HTML5中不推荐使用该标记(另请参阅:Why is the <center> tag deprecated in HTML?)。
为了轻松地将中间位置放在中间,您可以将输入元素包装在div中并相应地设置样式( display:table; margin-left:auto; margin-right:auto; )as在:
<div style="display:table;margin-left:auto;margin-right:auto;">
<input type="BUTTON" value="will be positioned in the center">
</div>
链接到fiddle
答案 1 :(得分:0)
为什么不像使用<center>
<center>
<FORM>
<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh">
</FORM>
</center>
此外,您的标记不正确,您有2个body
元素,请更正。
<body>
<SCRIPT LANGUAGE="JavaScript">
function iwarnedyou() {
intrvl = 0;
for (nTimes = 0; nTimes < 9999; nTimes++) {
intrvl += 1500;
setTimeout("document.bgColor='#8CD19D';", intrvl);
intrvl += 1500;
setTimeout("document.bgColor='#ACDEB2';", intrvl);
intrvl += 1500;
setTimeout("document.bgColor='#BFD8AD';", intrvl);
}
}
</SCRIPT>
<center>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Soooothe." onClick="iwarnedyou()" />
</FORM>
</center>
<br/>
<div style="clear:both"></div>
<div><a target="_blank" href="Georgeocodes.github.io/"><span style="font-size: 8pt; text-decoration: none">George O Codes</span></a>
</div>
<SCRIPT LANGUAGE="JavaScript">
function iwarnedu() {
intrvl = 0;
for (nTimes = 0; nTimes < 9999; nTimes++) {
intrvl += 100;
setTimeout("document.bgColor='#FFFFFF';", intrvl);
intrvl += 100;
setTimeout("document.bgColor='#000000';", intrvl);
}
}
</SCRIPT>
<center>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Nightmare. [Warning: Flashing]" onClick="iwarnedu()" />
</FORM>
</center>
<center>
<FORM>
<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh" />
</FORM>
</center>
</body>
注意:强>
HTML5中的中心元素已经过时了,我建议你改用CSS。
答案 2 :(得分:0)
您没有将重置按钮包装在中心标签中。
此
<FORM>
<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh">
</FORM>
</body>
应该是这样的
<center>
<FORM>
<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh">
</FORM>
</center>
</body>
(我为美观和易读性添加了一些缩进。编写漂亮的代码绝不会让人痛苦。)