我的jquery正确吗?
我想知道我的 jquery 函数是否正确
<script>
window.blinker = setInterval(function(){
if(window.alerta){
$('a.cadastrotopo').css('color','#346698');
$('a.cadastrotopo').css('text-decoration','underline');
window.alerta=false;
}
else{
$('a.cadastrotopo').css('color','#000');
$('a.cadastrotopo').css('text-decoration','none');
window.alerta = true;
}
},500);
</script>
工作正常,但我想知道我的方法是否正确。
我谢谢你。
I am wondering if my jquery function is correct
<script>
window.blinker = setInterval(function(){
if(window.alerta){
$('a.cadastrotopo').css('color','#346698');
$('a.cadastrotopo').css('text-decoration','underline');
window.alerta=false;
}
else{
$('a.cadastrotopo').css('color','#000');
$('a.cadastrotopo').css('text-decoration','none');
window.alerta = true;
}
},500);
</script>
is working ok, but I wonder if I'm doing the right way.
I thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我会更多地使用 CSS,特别是类:
然后解决方案就变得微不足道:
旁注:您可以使用匿名对象来指定多个属性,而不是多个
css()
调用。话虽这么说,我不喜欢像这样使用硬编码的 CSS 操作。青睐班级。它们更加灵活,您不必担心破坏性的更改并将其回滚。
Personally I would use CSS more, particularly classes:
and then the solution becomes trivial:
One side note: instead of multiple
css()
calls you can use anonymous objects to specify multiple properties.That being said, I prefer not to use hardcoded CSS manipulation like this. Favour classes. They're far more flexible and you don't have to worry about destructive changes and rolling them back.
是的,确实如此,尽管您可以将 css 声明组合起来,如下所示。
Yes, you are, although you could combine the css declarations to look like this.