[英]Special char jquery
I have a problem with >
我对
>
有疑问and jquery datatable shows '>' fine but when I click on the row I get the character >
和 jquery 数据表显示 '>' 很好,但是当我单击该行时,我得到字符
>
and I'm desperate.我很绝望。
Any solution?任何解决方案?
$('#sample tbody').on('click', 'tr', function() {
//console.log(table.row(this).data());
$(".modal-bodya div span").text("");
$(".new span").text(dataTable.row(this).data()[2]);
The issue is because you're using text()
, which does not encode HTML entities.问题是因为您使用的是
text()
,它不会对 HTML 实体进行编码。 To get the output you expect use html()
instead.要获得您期望的 output,请改用
html()
。
let value = 'foo > bar'; $(".text span").text(value); $(".html span").html(value);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <div class="text">Text: <span></span></div> <div class="html">HTML: <span></span></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.