这是我的功能......它完美地运作,基本上它回应了主框架的100个结果......这只是我使用这个闪烁的原因,我需要一种关闭它的方法.....赞赏任何帮助
<script>
function blink(f,t,c,n) {
var f; // Function
var t; // Time
var c; // Color
var n; // Next Color
var y; // Test Variable
if (f===undefined) {
setTimeout('blink("LOCKED", 100,"#004400","#00FF00")',100);
setTimeout('blink("DISABLED", 300,"#888800","#FFFF00")',300);
setTimeout('blink("READY", 200,"#004400","#008800")',200);
setTimeout('blink("MARKEDOUT",500,"#772000","#FFbb00")',500);
}
else {
var x = document.getElementsByClassName("chip");
var len = x.length;
for (var i=0; i<len; i++) {
y=x[i].title;
if (x[i].title==f) {
if (Math.random()>.5){
x[i].style.backgroundColor=c;
}
}
} // end chip for loop
x = document.getElementsByClassName("chipr");
var len = x.length;
for (var i=0; i<len; i++) {
y=x[i].style.backgroundColor;
if (x[i].title==f) {
if (Math.random()>.5){
x[i].style.backgroundColor=c;
}
}
} // end chipr for loop
y="blink('" + f + "'," + t + ",'" + n + "','" + c + "')" ;
c="zzz";
setTimeout(y,t);
c="xxx";
} // end else
c="www";
} // end of "blink"
.</script>
我的HTML代码分为两个地方:
<! One body tag enables blinking, the other does not >
<!body onload="blink();MM_preloadImages('images/gold.png','images/goldset.png')">
<body MM_preloadImages('images/gold.png','images/goldset.png')">
这是光明的部分......
<div class="statcontainer">
<div class="chip" id="b37:00" style="background-color: <?php echo $cccd0 ['BRD 37']?>" title="<?php echo $ccstat[0]['BRD 37']?>"> </div>
<div class="chip" id="b37:01" style="background-color: <?php echo $cccd1['BRD 37']?>" title="<?php echo $ccstat[1]['BRD 37']?>"> </div>
<div class="chip" id="b37:02" style="background-color: <?php echo $cccd2['BRD 37']?>" title="<?php echo $ccstat[2]['BRD 37']?>"> </div>
<div class="chip" id="b37:03" style="background-color: <?php echo $cccd3['BRD 37']?>" title="<?php echo $ccstat[3]['BRD 37']?>"> </div>
<div class="chipr" id="b37:07" style="background-color: <?php echo $cccd4['BRD 37']?>" title="<?php echo $ccstat[4]['BRD 37']?>"> </div>
<div class="chipr" id="b37:06" style="background-color: <?php echo $cccd5['BRD 37']?>" title="<?php echo $ccstat[5]['BRD 37']?>"> </div>
<div class="chipr" id="b37:05" style="background-color: <?php echo $cccd6 ['BRD 37']?>" title="<?php echo $ccstat[6]['BRD 37']?>"> </div>
<div class="chipr" id="b37:04" style="background-color: <?php echo $cccd7['BRD 37']?>" title="<?php echo $ccstat[7]['BRD 37']?>"> </div>
</div>
然后您可能需要包含$ ccstat
的变量<?php
$cccd0 = array();
$ccstat = array(); // two dimensional array to hold status that will be board-chip status as a title
if (($handle = fopen($statfile, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
if(substr(trim($data[0]), 0, 3) == 'BRD')
{
$board = trim($data[0]);
$temp = trim($data[2]);
list($temp,$status)=explode(" ",$temp,2); // First token (color) into temp. Rest of field into status
$cccd0[ $board ] = $temp;
$ccstat[0][$board]=$status; // mainjob will display this as a title on the div i.e. a "tooltip"
}
}
fclose($handle);
}
?>
答案 0 :(得分:0)
您可以使用window.clearTimeout(myTimeout);
清除超时,但需要将其分配给变量。
// HTML
<span onclick="killLoop();">Cancel blink!</span>
<span onclick="startLoop(f,t,c,n);">Start blink!</span>
// JS
window.myTimeout = false;
startLoop = function (f,t,c,n) {
if (window.myTimeout === false) blink(f,t,c,n);
}
killLoop = function () {
if (window.myTimeout !== false) {
window.clearTimeout(window.myTimeout);
window.myTimeout = false;
}
}
function blink(f,t,c,n) {
...
window.myTimeout = setTimeout(y,t);
...
}