我有一个问题与>
和jquery数据表显示'>'很好,但当我点击行我得到字符>
,我很绝望。
解决方案吗?
$('#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]);
问题是因为您正在使用text()
,它不编码HTML实体。要获得您期望的输出,请使用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>