【问题标题】:jsonGenerator cannot pass strings with whitespacejsonGenerator 不能传递带有空格的字符串
【发布时间】:2014-06-01 21:42:50
【问题描述】:

您好,我有一个问题,我无法将包含空格的字符串值传递给 js 函数,我正在使用 jsonGenerator,这是我的代码:

jGenerator.writeStringField(cols[8],ap.getContentId() != null ? "<img src='img/active.png' onclick=authorizeContent("+ap.getContentId()+","+ ap.getName()+"); style='cursor:pointer;margin:0px 5px;width:18px;height:18px;'/>  <img src='img/delete.png' onclick=authorizeContent('"+ ap.getContentId() +"','"+ ap.getName()+"'); style='cursor:pointer;margin:0px 5px;width:18px;height:18px;'/>" : "");

这是生成的 HTML

<td class="center"><img src="img/active.png" onclick="authorizeContent(47,la" diabla);="" style="cursor:pointer;margin:0px 5px;width:18px;height:18px;">  <img src="img/delete.png" onclick="authorizeContent('47','la" diabla');="" style="cursor:pointer;margin:0px 5px;width:18px;height:18px;"></td>

请帮忙,我也尝试过这种方法但没有成功:

        jGenerator.writeStringField(cols[8],ap.getContentId() != null ? "<img src='img/active.png' onclick=authorizeContent('"+ ap.getContentId() +"','"+ ap.getName()+"'); style='cursor:pointer;margin:0px 5px;width:18px;height:18px;'/>  <img src='img/delete.png' onclick=authorizeContent('"+ ap.getContentId() +"','"+ ap.getName()+"'); style='cursor:pointer;margin:0px 5px;width:18px;height:18px;'/>" : "");

和html

<td class="center"><img src="img/active.png" onclick="authorizeContent('47','la" diabla');="" style="cursor:pointer;margin:0px 5px;width:18px;height:18px;">  <img src="img/delete.png" onclick="authorizeContent('47','la" diabla');="" style="cursor:pointer;margin:0px 5px;width:18px;height:18px;"></td>

【问题讨论】:

    标签: java javascript html json


    【解决方案1】:

    使用这种方式修复:

            jGenerator.writeStringField(cols[8],"<img onclick=\"authorizeContent('"+ ap.getContentId() +"','"+ ap.getName().trim() +"');\" style=\"cursor:pointer;margin:0px 5px;width:18px;height:18px;\" src=\"img/active.png\" /> <img onclick=\"authorizeContent('"+ ap.getContentId() +"','"+ ap.getName().trim() +"');\" style=\"cursor:pointer;margin:0px 5px;width:18px;height:18px;\" src=\"img/delete.png\" />");
    

    【讨论】:

      猜你喜欢
      • 2013-10-21
      • 1970-01-01
      • 2019-06-09
      • 2013-07-04
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多