#####JavaScript escape() 函数定义和用法

escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串。

语法:

escape(string)

例子:

<!DOCTYPE html>
<html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"><script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script><style></style></head><body></body><script>document.write(escape("wang xiaoting!") + "<br />")document.write(escape("?!=()#%&"))</script>
</html>

#####JavaScript unescape() 函数定义和用法

unescape() 函数可对通过 escape() 编码的字符串进行解码。

语法:

unescape(string)

在本例中,我们将使用 escape() 来编码字符串,然后使用 unescape() 对其解码:

<!DOCTYPE html>
<html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"><script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script><style></style></head><body></body><script type="text/javascript">var test1="wang  xiao ting !"test1=escape(test1)document.write (test1 + "<br />")test1=unescape(test1)document.write(test1 + "<br />")</script>
</html>

举个栗子:

实际应用在项目里面

html

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>Dashboard | Nadhif - Responsive Admin Template</title><link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"><link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap-table/1.15.4/bootstrap-table.min.css"><script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script><script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script><script src="https://cdn.bootcss.com/bootstrap-table/1.15.4/bootstrap-table.min.js"></script><script src="https://cdn.bootcss.com/bootstrap-table/1.15.4/locale/bootstrap-table-zh-CN.min.js"></script></head><style>.page-content-wrapper {width: 800px;position: absolute;top: 10%;left: 24%;background: #fff;border: 1px solid #999;padding: 3% 0 0 9%;display: none;}.inputstyle {width: 60%;height: 34px;padding: 6px 12px;font-size: 14px;line-height: 1.42857143;color: #555;background-color: #fff;background-image: none;border: 1px solid #ccc;border-radius: 4px;}</style><body><table id="mytab" class="table table-hover"></table><!-- 新增和修改界面 --><div class="page-content-wrapper"><input type="text" class="inputstyle" id="id" style="display: none;"><div class="form-group"><label>工号:</label> <input type="text" class="inputstyle" id="deviceId"></div><div class="form-group"><label>姓名:</label> <input type="text" class="inputstyle" id="name"></div><div class="form-group"><label>电话:</label> <input type="text" class="inputstyle" id="phone"></div><div class="form-group"><label>公司:</label> <input type="text" class="inputstyle" id="organName"></div><div class="modal-footer"><button type="button" class="btn default" data-dismiss="modal" id="close">关闭</button><button type="button" class="btn blue" id="addBtn">保存</button></div></div><script>$('#mytab').bootstrapTable({method: 'get',url: "test.json", // 请求路径striped: true, // 是否显示行间隔色pageNumber: 1, // 初始化加载第一页pagination: true, // 是否分页sidePagination: 'client', // server:服务器端分页|client:前端分页pageSize: 5, // 单页记录数pageList: [5, 20, 30],// showRefresh : true,// 刷新按钮queryParams: function(params) { // 上传服务器的参数var temp = {};return temp;},columns: [{title: 'id',field: 'id',visible: false}, {title: '工号',field: 'deviceId',}, {title: '姓名',field: 'name',}, {title: '联系电话',field: 'phone'}, {title: '公司部门',field: 'organName'}, {title: '操作',field: 'id',formatter: option}]})// 定义删除、更新按钮function option(value, row, index) {var htm = "";htm = '<button id="upd"  onclick="update(\'' + escape(JSON.stringify(row)) + '\')">修改</button>';return htm;}function update(row) {$(".page-content-wrapper").show();var data = JSON.parse(unescape(row))$('#deviceId').val(data.deviceId)$('#name').val(data.name)$('#phone').val(data.phone)$('#organName').val(data.organName)}$("#close").on("click", function() {$(".page-content-wrapper").hide();})</script></body></html>

test.json

[{"id": 1,"deviceId": "43445","name": "王小婷","phone": "1567865475","organName": "字节跳动"},  {"id": 2,"deviceId": "53456","name": "最帅的坏兔子","phone": "1567865475","organName": "腾讯" },{"id": 3,"deviceId": "2345","name": "阿强","phone": "1567865475","organName": "360" },{"id": 4,"deviceId": "2345","name": "阿花","phone": "1567865475","organName": "百度" },{"id": 5,"deviceId": "2345","name": "阿奶","phone": "1567865475","organName": "蚂蚁金服" },{"id": 5,"deviceId": "2345","name": "阿狗","phone": "1567865475","organName": "阿里" }
]

首先使用escape对字符串进行编码,然后使用unescape() 函数对编码的字符串进行解码。

javascript escape()和unescape()区别相关推荐

  1. JavaScript编码encode和decode escape和unescape

    encodeURI() 函数可把字符串作为 URI 进行编码. 语法 encodeURI(URIstring) 参数 描述 URIstring 必需.一个字符串,含有 URI 或其他要编码的文本. 返 ...

  2. .net里面实现javascript中的 escape 和 unescape 功能

    javascript 脚本,有个 escape 和 unescape ,在做URL传递等的情况下, 用的比较多 到了.NET里面, 在 C# 和 VB.NET 下, 仍然有很多人想使用这种功能, 但是 ...

  3. JavaScript escape/unescape 编码的 Java 实现

    /** * JavaScript escape/unescape 编码的 Java 实现 * author jackyz * keep this copyright info while using ...

  4. js escape、 unescape、 encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别

    js 1.5版本之后escape. unescape(已弃用)尽量不推荐使用 1.作用 escape是对字符串(string)进行编码(而另外两种是对URL),作用是让它们在所有电脑上可读 2. en ...

  5. 在VB6.0中怎么实现escape和unescape

    两套方案,一是调用JAVAscript对象,二是自己写代码编码与解码,代码在CSDN中的以下帖子里贴出: 方案一代码: 复制内容到剪贴板 程序代码 Function Escape(ByVal pstr ...

  6. escape()和unescape()函数的使用方法

    (一).示例图片效果 (二).代码 <html> <head> <title>escape()和unescape()函数的使用方法</title> &l ...

  7. escape()与unescape()

    浏览器与服务器通信的时候,许多常见的非文字数字字符(如空格)不能以其原来的格式传输,只允许较少的字母.数字.和符号传输.为了使用其它字符,字母必须使用特殊的符号(%)和十六进制的ASCII值进行编码. ...

  8. java unescape_Java实现JS中的escape和UNescape代码分享

    众所周知,JavaScript中escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串.下面,我们就来看看 Java语言中类似JavaScript中的escape() 和un ...

  9. php js unescape,PHP实现JS中escape与unescape的方法

    本文实例讲述了PHP实现JS中escape与unescape的方法.分享给大家供大家参考,具体如下: JavaScript中的escape和unescape是吧字符串转换为unicode十六进制编码, ...

最新文章

  1. Keras卷积+池化层学习
  2. xshell中mysql命令大全_Linux之Xshell脚本代码实例
  3. 拖链电缆 机器人电缆_尼龙拖链在机器中起着电缆的作用
  4. 【新品发布】山海软件生产线pspl,包含了一个开源的混淆器
  5. asp.net控件库FineUI使用入门图解
  6. 安装教程_Typora+Pandoc导出word
  7. php mysql odbc_javascript连接mysql与php通过odbc连接任意数据库的实例
  8. 阿拉伯数字转化为中文汉字(大、小写) - PHP
  9. 三人小组关系c语言编程,理性分析一下c-block三人组的实力
  10. Oracle dataGuard专题:Rman通过duplicate创建standby
  11. 支付宝借呗还款利息为什么都不一样?
  12. php output详解,【PHP】Output Control 扩展详细解读
  13. Hadoop2.7.3伪分布式集群搭建
  14. CODE[VS] 1474 十进制转m进制
  15. 为VS2005添加X64编译平台
  16. python在线题库推荐_Python题库.docx
  17. 法正 (21) :端午
  18. kafka-topics.sh脚本详解
  19. Linux下system () 函数详解简介
  20. SecureCRT for Linux

热门文章

  1. 爬虫css解密 大众点评
  2. 解决IE6兼容性问题常见方法
  3. 德国基尔大学 计算机系,德国基尔大学强大的学术能力介绍
  4. 芜湖市荟萃中学计算机课老师名单,做智慧型班主任 ——芜湖荟萃中学召开班级工作经验交流暨班主任培训会...
  5. python画k线图_Python使用matplotlib绘制k线图(去掉空白日期)
  6. 【树莓派】树莓派使用python、E16 GPRS模块向MQTT服务器传输数据
  7. mysql分组查询 groud by
  8. KBPC3510-ASEMI电磁炉专用整流桥KBPC3510
  9. Source Insight4.0的安装教程及使用
  10. 送给她一朵漂亮的百合花(Matlab代码实现)