jqGrid 将行变成超连接时浏览器解析超连接错误

1、将行变成超连接如下所示

name: "CurrentScore", index: "CurrentScore", width: 80, align: "center", formatter: 
                            function (cellValue, options, rowdata, action) {
                                return "<a href='#' onclick=" + "ScoreDetail('" + rowdata.PassportNumber + "')" + ">考核详情</a>";
                               
                            }

2、解析成的超连接如下所示

3、问题原因
    通过排查问题,发现是传入的参数 rowdata.PassportNumber 带有空格,在生成超连接的时候被当成了换行符,而js在拼字符串的时候,如果换行了之后是会被截断的,就生成了上面的超连接。
4、解决问题
    找到问题原因后解决问题就简单了,去掉参数后面的空格就行了
function Trim(str) {
                return str.replace(/(^\s*)|(\s*$)/g, "");
            }
  

猜你喜欢

转载自www.cnblogs.com/zhengwei-cq/p/9472357.html