我需要得到一個幫助「的setInterval(函數(){}」功能,我的代碼工作setInterval函數 - 查詢
功能應顯示彈出消息時,黃色細胞數等於數。紅色單元格,我在下面列出了我的代碼和概念圖片,請幫助!:-)
這是我想要執行彈出消息的JavaScript。
setInterval(function(){
var reds = document.getElementByClassName('red_block')
var yellows = document.getElementByClassName('yellow_block')
if(reds.length == yellows.length){
alert("what ever")
}
}, 1);
這是我現在的代碼。
$(document).ready(function() {
var color = "White";
$("#btnWhite").click(function() {
color = "#FFFFFF"
});
$("#btnYellow").click(function() {
color = "#FFFF00"
});
$("#btnRed").click(function() {
color = "#FF0000"
});
$("table tr td").click(function() {
$(this).css("background-color", color);
});
});
body {
padding: 5px;
}
label {
font-weight: bold;
}
input[type=button] {
padding: 10px 16px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
p {
margin: 1em 0 0;
}
td.pz {
border: thin solid #000000;
width: 59px;
height: 57px;
background-color: #FFFFFF;
}
.red_block {
border: thin solid #000000;
width: 59px;
height: 57px;
background-color: #FF0000;
}
.yellow_block {
border: thin solid #000000;
width: 59px;
height: 57px;
background-color: #FFFF00;
}
td.padding {
width: 59px;
height: 57px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<br>
<br>
<input id="btnWhite" type='button' style="font-face: 'Arial'; width: 50px; font-size: larger; color: Black; background-color: #FFFFFF; border: 1px dotted #999" value="">
<input id="btnYellow" type='button' style="font-face: 'Arial'; width: 50px; font-size: larger; color: Black; background-color: #FFFF00; border: 1px dotted #999" value="">
<input id="btnRed" type='button' style="font-face: 'Arial'; width: 50px; font-size: larger; color: Black; background-color: #FF0000; border: 1px dotted #999" value="">
<br>
<br>
<table>
<tr>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
</tr>
<tr>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
</tr>
<tr>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
</tr>
<tr>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
</tr>
<tr>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="yellow_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
<td class="red_block"></td>
</tr>
</table>
</body>
你必須結束與各線; –
爲什麼你需要'setInterval'?更改後可以檢查每種顏色的盒子的長度,不是嗎? –
除了沒有結束帶終止符(;)的行之外,您究竟在哪裏調用了代碼中的setInterval函數? –