gpt4 book ai didi

javascript - 如何更改附加元素的颜色?

转载 作者:行者123 更新时间:2023-11-30 15:41:59 25 4
gpt4 key购买 nike

我创建了一个“自定义附加”函数,它接受两个参数并将它们的值附加在一行中。 我需要使第一个参数的值以灰色附加,但第二个值必须保持原样。我尝试使用“css(property, name)”函数,但没有用。我的谬误在哪里以及如何获得所需的结果?

var showText = function(who, str) {
if (str !== "") {
var colorWho = who.name;
colorWho.css("color", "gray");
$("#storyBoard").append("<br>" + colorWho + ": " + str + "<br>");
var element = document.getElementById("storyBoard");
element.scrollTop = element.scrollHeight;
}
};

最佳答案

给你

Fiddle

CSS

p > span {          /* If you're going to take this to a larger environment, you may want to use classes instead */
color:gray;
}

JS

var showText = function(who, str) {
if(str !== ""){
var colorWho = who.name;
$("#storyBoard").append("<p><span>"+colorWho + "</span>: " +str+ "<p>");
}

};

var obj = {
name : "Preacher",
}

showText(obj, "Is an awesome comic book !");

关于javascript - 如何更改附加元素的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40651531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com