博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JS及JQuery对Html内容编码,Html转义
阅读量:4599 次
发布时间:2019-06-09

本文共 668 字,大约阅读时间需要 2 分钟。

/** JQuery Html Encoding、Decoding* 原理是利用JQuery自带的html()和text()函数可以转义Html字符* 虚拟一个Div通过赋值和取值来得到想要的Html编码或者解码*/ 
//编码	function html_encode(str)	{		var s = "";		if (str.length == 0) return ""; s = str.replace(/&/g, ">"); s = s.replace(//g, ">"); s = s.replace(/ /g, " "); s = s.replace(/\'/g, "'"); s = s.replace(/\"/g, """); s = s.replace(/\n/g, "
"); return s; } //解码 function html_decode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/>/g, "&"); s = s.replace(//g, ">"); s = s.replace(/ /g, " "); s = s.replace(/'/g, "\'"); s = s.replace(/"/g, "\""); s = s.replace(/
/g, "\n"); return s; }

转载于:https://www.cnblogs.com/xiaoleiel/p/8308774.html

你可能感兴趣的文章
[luogu4310] 绝世好题 (递推)
查看>>
[luogu3203 HNOI2010] 弹飞绵羊 (分块)
查看>>
-Dmaven.multiModuleProjectDirectory system propery is not set.
查看>>
Python2 unichr() 函数
查看>>
Python 字典 copy()方法
查看>>
Minimum Path Sum
查看>>
Remove Duplicates from Sorted Array II
查看>>
常量指针和指针常量巧妙记忆方法[转]
查看>>
python-haproxy作业讲解视频总结
查看>>
批处理文件脚本总结
查看>>
快速排序C++代码
查看>>
mui搜索框 搜索点击事件
查看>>
bzoj 5289: [Hnoi2018]排列
查看>>
IE10 招贤纳意问题整理文章-安装卸载、功能设置篇
查看>>
joomla处境堪忧
查看>>
Jquery-AJAX
查看>>
python 在windows环境下 压缩文件
查看>>
CSS 动画总结
查看>>
mysql命令gruop by报错this is incompatible with sql_mode=only_full_group_by
查看>>
LeetCode55 Jump Game
查看>>