asp*_*pie 0 html javascript internet-explorer
我自愿为一个小型组织开发这个脚本(作为我编程自我训练的一部分).它随机选择一个房间的座位(花几秒钟让观众猜测选择了哪个座位).由于我使用的是Mac,我主要使用Firefox测试,它的功能就像一个魅力.事实证明,他们房间的计算机在Windows XP上运行Internet Explorer 6(他们必须在本地文件中启用活动内容).
他们叫我告诉我一个错误,根据他们给出的信息,有罪的行是RowNumberDisplay.style = "color: #FF0000";或者var RowNumberDisplay = document.getElementById("RowNumber");.在IE6上快速搜索getElementById和.style问题的谷歌和Stack Overflow是徒劳的(一个常见的问题是由于名称属性导致的错误匹配,但有问题的div没有名称属性).提前感谢任何有助于识别和解决此错误的答案.
<!doctype html>
<html>
<head>
<title>The Lucky Person</title>
<style type="text/css">
input#SelectLuckyPerson
{
height: 150px;
font-size: 60px;
}
p#RowDetails, p#SeatDetails, div#RowNumber, div#SeatNumber
{
font-size: 100px;
display: inline;
}
div#RowNumber, div#SeatNumber
{
color: #0000FF;
}
</style>
</head>
<body>
<div id="LuckyPersonIs"><input type="button" id="SelectLuckyPerson" value="And the lucky person is..." onClick="GetResults();"></div>
<p id="RowDetails">Row number: <div id="RowNumber">0</div></p>
<p id="SeatDetails">Seat number: <div id="SeatNumber">0</div></p>
<script>
var MinRow = 2;
var MaxRow = 8;
var SeatsInRow = new Array();
SeatsInRow[1] = 25;
SeatsInRow[2] = 25;
SeatsInRow[3] = 27;
SeatsInRow[4] = 27;
SeatsInRow[5] = 27;
SeatsInRow[6] = 27;
SeatsInRow[7] = 29;
SeatsInRow[8] = 31;
SeatsInRow[9] = 31;
SeatsInRow[10] = 31;
SeatsInRow[11] = 31;
SeatsInRow[12] = 33;
SeatsInRow[13] = 33;
SeatsInRow[14] = 33;
var ShuffleSpeed = 200;
var RowNumberDisplay = document.getElementById("RowNumber");
var SeatNumberDisplay = document.getElementById("SeatNumber");
var ChosenRow, ChosenSeat
function GetResults()
{
var IsRunning = CheckStatus();
if (IsRunning)
{
ChosenRow = ChooseRow();
ChosenSeat = ChooseSeat();
RowNumberDisplay.style = "color: #FF0000";
SeatNumberDisplay.style = "color: #FF0000";
ShowRowResult = window.setInterval("TryRowResult()", ShuffleSpeed);
if (DelaySeats == false)
{
ShowSeatResult = window.setInterval("TrySeatResult()", ShuffleSpeed);
}
}
}
function ChooseRow()
{
return Math.floor(Math.random() * (MaxRow - MinRow)) + MinRow;
}
function ChooseSeat()
{
return Math.ceil(Math.random() * SeatsInRow[ChosenRow]);
}
function TryRowResult()
{
TryRow = ChooseRow();
RowNumberDisplay.innerHTML = TryRow;
if (TryRow == ChosenRow)
{
window.clearInterval(ShowRowResult);
document.getElementById("RowNumber").style = "color: #0000FF";
if (DelaySeats == true)
{
ShowSeatResult = window.setInterval("TrySeatResult()", ShuffleSpeed);
}
}
}
function TrySeatResult()
{
TrySeat = ChooseSeat();
SeatNumberDisplay.innerHTML = TrySeat;
if (TrySeat == ChosenSeat)
{
window.clearInterval(ShowSeatResult);
document.getElementById("SeatNumber").style = "color: #0000FF";
}
}
function CheckStatus()
{
if (RowNumberDisplay.style.color == "rgb(255, 0, 0)" || SeatNumberDisplay.style.color == "rgb(255, 0, 0)")
{
return false;
}
return true;
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
元素的style属性是对象,而不是字符串.要像分配CSS属性一样为文本分配文本,您应该分配给它element.style.cssText,这将为您解析字符串,并充当定义多个样式的快捷方式.
但是,在这种情况下,你可以使用这个:
ChosenRow.style.color = ChosenSeat.style.color = "#f00";
Run Code Online (Sandbox Code Playgroud)