Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 用jQuery追加样式标记_Javascript_Jquery_Html_Append - Fatal编程技术网

Javascript 用jQuery追加样式标记

Javascript 用jQuery追加样式标记,javascript,jquery,html,append,Javascript,Jquery,Html,Append,我正在尝试使用socket.io在我的网站上建立一个基本的聊天室。我有基本的功能,但我想加粗我的一个输入字段。我已经试过了 $('#messages').append($('<li>').text('<strong>'+msg.user+': </strong>'+msg.message)); $(“#消息”).append($(“”).text(“”+msg.user+”:”+msg.message)); 最后它只是添加了,字面上是。我应该如何将其格式设

我正在尝试使用socket.io在我的网站上建立一个基本的聊天室。我有基本的功能,但我想加粗我的一个输入字段。我已经试过了

$('#messages').append($('<li>').text('<strong>'+msg.user+': </strong>'+msg.message));
$(“#消息”).append($(“
  • ”).text(“”+msg.user+”:”+msg.message));

  • 最后它只是添加了,字面上是
    。我应该如何将其格式设置为实际加粗的“msg.user”?

    而不是使用
    .text
    ,尝试使用
    .html

    您可以使用.html()代替.text()

    $(“#消息”).append($(“”).html(“”+msg.user+”“+msg.message));
    
    use.html not.text谢谢!我知道这一定是我忽略的简单的事情。
    $("#messages").append( $("<div>").html("<strong>" + msg.user + "</strong>" + msg.message));