Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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
使用.append()+;使用Jquery/Javascript添加新文本的css/样式_Javascript_Jquery_Html_Css - Fatal编程技术网

使用.append()+;使用Jquery/Javascript添加新文本的css/样式

使用.append()+;使用Jquery/Javascript添加新文本的css/样式,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想向已有的选择器添加新的html,因此我认为需要使用.append()。同时我还想让新的字符串变成不同的颜色、字体等 我希望最后一个.css只使新的附加html变成粉红色(或其他),而不是测试字符串。任何指点都很好 由于最后一个.css,下面的代码不起作用。我该如何解决这个问题?谢谢 test_string = "hi there,"; $('#testie').html(test_string).css("font-size", "40px").append(" pink strin

我想向已有的选择器添加新的html,因此我认为需要使用.append()。同时我还想让新的字符串变成不同的颜色、字体等

我希望最后一个.css只使新的附加html变成粉红色(或其他),而不是测试字符串。任何指点都很好

由于最后一个.css,下面的代码不起作用。我该如何解决这个问题?谢谢

  test_string = "hi there,";
  $('#testie').html(test_string).css("font-size", "40px").append(" pink string").css('color', 'pink');

(注意:Javascript/Jquery一般都是新手,因此欢迎提供任何帮助/建议)

对新字符串使用
span

test_string=“你好,”;
$('body').html(test_string).css(“字体大小”,“40px”);
var newtext=$('').css('color','pink');
html(“粉红字符串”);
$('body').html(测试字符串).css(“字体大小”,“40px”).append(新文本)

您不能向文本添加样式,您需要创建一个新元素,可以是DIV,也可以是SPAN,然后将样式放在那里。