3

我正在尝试将 HTML 文本传递给我div,我需要将此字符串呈现为 HTML 元素,我的代码:

<div id="divchat" style="width: 500px; height: 300px; border: 2px solid brown;"/></div>
@Html.TextBoxFor(model => model.msj) 
<button type="submit" id="btnSend">Send</button>

<script>
    $(function(){
          var chatNS = '@HttpContext.Current.Application["Chateo"].ToString()';
          $("#divchat").append(chatNS);
    });
</script>

div显示内容就像一个字符串,我怎样才能让 HTML 元素正确呈现到divchat

4

2 回答 2

2

你试过把你HttpContext.Current.Application["Chateo"]的包裹起来@Html.Raw()吗?

<script>
    $(function(){
      var chatNS = '@Html.Raw(HttpContext.Current.Application["Chateo"])';
      $("#divchat").append(chatNS);
    });
</script>
于 2013-04-08T07:06:54.243 回答
0

尝试

$("#divchat").html(chatNS);
于 2013-04-08T07:10:50.780 回答