Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果标量变量>;0,Perl_Javascript_Jquery_Html_Css_Perl - Fatal编程技术网

Javascript 如果标量变量>;0,Perl

Javascript 如果标量变量>;0,Perl,javascript,jquery,html,css,perl,Javascript,Jquery,Html,Css,Perl,我有一个带有通知系统的标题,在mail1.png旁边有一个整数,如下所示: <div class = "header"> <a class="notifications-dropdown-trigger"><b id="num-posts"><%= (scalar @post_regular) %></b> <img src="/images/icons/mail1.png" /></a> </d

我有一个带有通知系统的标题,在
mail1.png
旁边有一个整数,如下所示:

<div class = "header">
     <a class="notifications-dropdown-trigger"><b id="num-posts"><%= (scalar @post_regular) %></b> <img src="/images/icons/mail1.png" /></a>
</div>

scalar@post_regular
检索并以整数形式显示该用户在数据库中的通知量

我想实现一些东西,只要
scalar@post_regular
大于0,就会改变它旁边的图像以及数字的背景色。因此,当用户至少有一个通知时,我希望它旁边的图像显示
mail2.png
而不是
mail1.png
,并且背景颜色为
red
而不是默认颜色


我认为这种方法应该用javascript解决?我不太熟悉它,也不知道如何处理它。

只需将逻辑添加到您的img src中:

<img src="/images/icons/mail<%= @post_regular ? 2 : 1 %>.png" />
.png”/>

类似的功能可用于调整样式,但我可能建议注入二级类来设置背景色,而不是硬编码样式。

只需将逻辑添加到img src:

<img src="/images/icons/mail<%= @post_regular ? 2 : 1 %>.png" />
.png”/>

类似的功能可用于调整样式,但我可能建议注入二级类来设置背景色,而不是硬编码样式。

只需将逻辑添加到img src:

<img src="/images/icons/mail<%= @post_regular ? 2 : 1 %>.png" />
.png”/>

类似的功能可用于调整样式,但我可能建议注入二级类来设置背景色,而不是硬编码样式。

只需将逻辑添加到img src:

<img src="/images/icons/mail<%= @post_regular ? 2 : 1 %>.png" />
.png”/>

类似的功能可用于调整样式,但我可能建议注入一个辅助类来设置背景色,而不是硬编码样式。

您能向我解释一下
?2:1
功能吗。我以前从未使用过它,最近才开始使用Perl。另外,我可以用单词代替
2:1
.png/>
三元“?:是,就像在C中一样。它的工作原理很像if-then-else。此外,您可以使用单词作为返回值,只要您将它们括在引号中,并将它们作为字符串处理。所有内容都有意义并且工作正常,谢谢您能向我解释一下
?2:1
功能吗。我以前从未使用过它,最近才开始使用Perl。另外,我可以用单词代替
2:1
.png/>
三元“?:是,就像在C中一样。它的工作原理很像if-then-else。此外,您可以使用单词作为返回值,只要您将它们括在引号中,并将它们作为字符串处理。所有内容都有意义并且工作正常,谢谢您能向我解释一下
?2:1
功能吗。我以前从未使用过它,最近才开始使用Perl。另外,我可以用单词代替
2:1
.png/>
三元“?:是,就像在C中一样。它的工作原理很像if-then-else。此外,您可以使用单词作为返回值,只要您将它们括在引号中,并将它们作为字符串处理。所有内容都有意义并且工作正常,谢谢您能向我解释一下
?2:1
功能吗。我以前从未使用过它,最近才开始使用Perl。另外,我可以用单词代替
2:1
吗,比如
.png/>
三元“:”是,就像在C中一样。它的工作原理非常类似于if-then-else。此外,您可以使用单词作为返回值,只要您将它们括在引号中,并因此将它们作为字符串处理。一切都很有意义,非常有效,谢谢