javascript - jquery .html 显示 html 标签,而不是在文本上应用 html 标签

标签 javascript jquery jquery-1.9

我的代码是

 printMsg : function(data) {
    $("#message").html(data.bodyText);
    ...
    }

这里

data.bodyText   =    <strong> Test This Text  ;/strong>

我应该将数据显示为测试此文本并且我这样做了

 $("#message").html(data.bodyText);

这可以正确显示 jquery 以前版本 (1.9) 的文本

现在使用 jquery 1.10 可以显示

<strong> Test This Text  </Strong>

您能告诉我原因吗?如果有的话有什么解决办法吗?

最佳答案

您是否尝试做类似 this? 的事情 在 jquery 1.10.1 中似乎工作正常

HTML

<span id='message'></span>

JS

var data = {};
data.bodyText = "<strong>Test This Text;</strong>"; 
$("#message").html(data.bodyText);

关于javascript - jquery .html 显示 html 标签,而不是在文本上应用 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975331/

相关文章:

javascript - Jquery 或 Javascript : How to find all html elements which has image more than 500px and less than 2000px?

javascript - 如何找到只知道 attr 值的对象的每个属性

javascript - 创建要在 CSS 中使用的 JavaScript 元素

javascript - 通过预览上传来动态更改图像

javascript - 如何使用 tinymce 的复选框按钮在运行时打开和关闭只读模式?

jquery - 更改 addthis 属性 `addthis:url` 并发送新的 URL 而不是加载的 URL?

javascript - 此 JS 代码是否等待 AJAX 请求完成?

javascript - fullpage.js - 在不在 fullpage.js 包装器中的 div 内滚动在 IOS 上是不可能的

jquery - 每个 HTML5 占位符属性有两种不同的样式?

javascript - 1.9.1 与 1.8.3 中的 Angular.js/jQuery html 字符串解析