JavaScript 改变文本颜色
我需要你的帮助。我有这个 javascript 函数可以将消息写入日志。日志文本颜色始终为蓝色。谁能解决这个问题吗?下面是我的 JavaScript 代码。
感谢您的帮助。
function logMessage(taskName,action,from,to)
{
var $logsDiv = jQuery("#logs");
var message = '';
if(action == "receive")
{
message = taskName +" was removed from '"+ from +"' and was added to '"+ to +"'<br/>";
jQuery("#logs").css("color","blue");
$logsDiv.append(message);
}
else
{
message = taskName +" was removed from '"+ from +"' and was added to '"+ to +"'<br/>";
jQuery("#logs").css("color","green");
$logsDiv.append(message);
}
}
I need your help. I have this javascript function to write a message to the logs. The logs text color is always blue. Anyone who can solve this issue? Below is my javascript code.
Thank you for your help.
function logMessage(taskName,action,from,to)
{
var $logsDiv = jQuery("#logs");
var message = '';
if(action == "receive")
{
message = taskName +" was removed from '"+ from +"' and was added to '"+ to +"'<br/>";
jQuery("#logs").css("color","blue");
$logsDiv.append(message);
}
else
{
message = taskName +" was removed from '"+ from +"' and was added to '"+ to +"'<br/>";
jQuery("#logs").css("color","green");
$logsDiv.append(message);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个代码
Try this code
问题是,每次添加新消息时,您还会对整个
#logs
进行着色,而不仅仅是消息。因此,不要使用:使用类似以下内容:
The problem is that, each time you add a new message, you also color your entire
#logs
instead of just the message. So instead of:use something like: