use*_*858 5 html javascript jquery jquery-plugins
我想知道是否有任何 jquery 组件可以自动处理特殊字符。这基本上意味着转换&为此处&列出的所有内容,以便当我将数据发送到后端时,它会以该格式存储。然后在检索时我们需要将其从 转换回。&&
我们将使用大量数学符号,因此我们需要 JavaScript 中的一个功能来实现这一点。我还看到了一个富文本编辑器,但我们不需要它的很多功能,例如图像、段落等,尽管我们希望文本编辑器有一些图标或一些东西来插入数学符号和源代码。简而言之,我正在寻找类似 Stackoverflow 编辑器的东西,但没有图像。
您可以使用 jQuery 来为您完成此操作:
\n\nfunction htmlEncode(value){\n if (value) {\n return jQuery(\'<div />\').text(value).html();\n } else {\n return \'\';\n }\n}\n\nfunction htmlDecode(value) {\n if (value) {\n return $(\'<div />\').html(value).text();\n } else {\n return \'\';\n }\n}\n\n\n$(document).ready(function() {\n alert( htmlEncode ("this is a & test") );\n});\nRun Code Online (Sandbox Code Playgroud)\n\n代码最初来自http://www.naveen.com.au/javascript/jquery/encode-or-decode-html-entities-with-jquery/289 .\xe2\x80\x8b
\n