0

我在使用 javascript 和 html 时遇到了一些麻烦。

这是我的脚本

<script type="text/javascript">
function flashtext(Urgent,col) {
var tmpColCheck = document.getElementById('Urgent').style.color;

  if (tmpColCheck === 'silver') {
    document.getElementById('Urgent').style.color = col;
  } else {
    document.getElementById('Urgent').style.color = 'silver';
  }
} 

setInterval(function() {
    flashtext('flashingtext','red');
}, 500 ); //set an interval timer up to repeat the function

这是我的 HTML,

<div class="js-col-md-6 js-col-xs-6" id="<?php echo $ticket->priority ?>" style="text-align: center; background:<?php echo $ticket->prioritycolour; ?>;"><?php echo $ticket->priority; ?></div>

id 是从后端设置调用的 Urgent,这是我想要闪烁/闪烁的唯一一个。

这就是问题所在,它有效=D yaay!...但仅在第一个实例上,所有其他紧急实例都是可靠的。所以我正在寻找的是如何让所有实例闪烁/闪烁而不仅仅是第一个实例?

谢谢 :)

4

2 回答 2

0

没关系,我解决了,为自己感到骄傲.. =)

对于其他有类似问题的人,这是如何完成的:

<div class="js-col-md-6 js-col-xs-6" id="<?php echo $ticket->priority ?>" style="text-align: center; background:<?php echo $ticket->prioritycolour; ?>;"><?php echo $ticket->priority; ?></div>

删除 id="" 并将 php 放在类中,如下所示:

<div class="js-col-md-6 js-col-xs-6 <?php echo $ticket->priority ?>" style="text-align: center; background:<?php echo $ticket->prioritycolour; ?>;"><?php echo $ticket->priority; ?></div>

现在向页面添加一个动画样式,我使用了:

<style>
.Urgent {
-webkit-animation-name: blinker;
-webkit-animation-duration: 1s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;

-moz-animation-name: blinker;
-moz-animation-duration: 1s;
-moz-animation-timing-function: linear;
-moz-animation-iteration-count: infinite;

animation-name: blinker;
animation-duration: 1s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}

@-moz-keyframes blinker {  
from { color: red; }
to { color: white; }
}

@-webkit-keyframes blinker {  
from { color: red; }
to { color: white; }
}

@keyframes blinker {  
from { color: red; }
to { color: white; }
}
</style>

这将归档的内容是将所有 .Urgent 类变成从红色到白色的渐变闪烁。如果您只是希望类消失而不是更改颜色,您也可以使用不透明度。

谢谢大家的回复。它驱使我找到解决方案 =)

于 2014-10-28T11:18:05.367 回答
0

我运行你的代码,如果你用你的 php 代码(包括括号)代替常量值,它就可以工作。我使用了“Urdgent”、#bbb 和 ccc。ccc 将不断闪烁。php.ini 一定有问题。

于 2014-10-28T07:45:08.670 回答