Datatable Jquery特殊字符对HTML的编码和解码 [英] Datatable Jquery special character encoding and decoding to HTML

查看:350
本文介绍了Datatable Jquery特殊字符对HTML的编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,当我们使用API​​函数从表对象中获取值时,诸如'&'之类的html特殊字符不会被解码,而是以ASCII或Unicode形式出现.这是我对dataTable的简单初始化.

I found out that html special characters such as '&' are not being decoded when we fetch value from the table object using API functions but instead of they are in ASCII or Unicode form. This is my simple initialization for the dataTable.

var otable = $('#vtable').DataTable({
        "dom": '<"top"lBf<"clear">>rt<"bottom"ip<"clear">>'
}); 

请参见小提琴.

什么是解码html特殊字符之前的最佳解决方案 传递给数据处理?

What should be best solution to decode html special character before passing it to the data processing?

推荐答案

编码HTML实体:

var valEncoded = $('<div>').text(val).html();

解码HTML实体:

var valDecoded = $('<div>').html(val).text();

有关代码和演示,请参见此示例.

See this example for code and demonstration.

请参见更新了jsFiddle ,以了解如何在项目中使用它.

See updated jsFiddle for demonstration on how it could be used in your project.

这篇关于Datatable Jquery特殊字符对HTML的编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆