拼接中文参数时,报错is not defined

简介: 拼接中文参数时,报错is not defined

相关文档

<!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": "阿里" 
    }
]

Uncaught ReferenceError: M43445 is not defined

at HTMLButtonElement.onclick (test.html:128)

报错原因:

具体原因是js把deviceId字符串当成一个变量对象,不能识别英文字母+数字类型的变量,在deviceId变量前后加上"转义字符,意思是",把deviceId最后以字符串类型参数传入到方法中

这个时候需要加个转义字符

\'' +row.deviceId+ '\'

相关文章
|
JSON 移动开发 应用服务中间件
调用Feign接口报错:JSON parse error:Illegal character ((CTRL-CHAR, code 31))
调用Feign接口报错:JSON parse error:Illegal character ((CTRL-CHAR, code 31))
3000 0
调用Feign接口报错:JSON parse error:Illegal character ((CTRL-CHAR, code 31))
|
9月前
|
Java
Java给指定URL字符串添加值和获取URL字符串中的参数值
Java给指定URL字符串添加值和获取URL字符串中的参数值
90 0
|
11月前
|
JSON PHP 数据格式
PHP中json传递请求字符串网址函数http_build_query()与parse_str(),将POST参数组转换拼接成GET请求链接
PHP中json传递请求字符串网址函数http_build_query()与parse_str(),将POST参数组转换拼接成GET请求链接
103 0
|
数据采集 Python
Python爬虫:urlencode带参url的拼接
Python爬虫:urlencode带参url的拼接
250 0
URL中符号& # ?等的作用
图片发自简书App + URL中+表示空格 / 分隔目录和子目录 ? 分隔实际的URL和参数 % 指定特殊字符 # 表示书签,打开浏览器会滑到哪个位置 & 指定的参数间的分隔符 = 指定参数的值
1269 0
|
JavaScript 前端开发 编解码
深入分析escape()、encodeURI()、encodeURIComponent()的区别及示例
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 。
841 0