日期:2014-05-19  浏览次数:20750 次

关于jstl中字符的转义(在线等待)
一个button的onclick事件如下:
onclick="return confirmDelete('${subFeatureName }');"

函数confirmDelete如下:
function confirmDelete(subMenuName)
{
alert(subMenuName);
var info="Are you sure you want to delete the sub menu "+subMenuName+" ?";
return confirm(info);
}

我想把中的${subFeatureName }的单引号给替换成"\'",我的代码如下所示:
<c:set var="subFeatureName " value="${fn:replace(subFeatureName , '\'', '\\\'')}"/>
但是始终报这个错误:
"${fn:replace(subFeatureName, ''', '\'')}" contains invalid expression(s): javax.servlet.jsp.el.ELException: Encountered "', '", expected one of [".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", ")", ",", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"]

请高手帮忙将参数${subFeatureName }中的单引号转换成"\'"
因为当调用onclick="return confirmDelete('Who's Book?');"是会报错,而之行onclick="return confirmDelete('Who\'s Book?');"就是对的。
还请高手帮忙解决!在线等待

------解决方案--------------------
subFeatureName 
你应该提前用java代码替换好了不就行了。何必这里做
------解决方案--------------------
该这里:

onclick="return confirmDelete(\"${subFeatureName }\");"
------解决方案--------------------

------解决方案--------------------
<c:set var="subFeatureName " value="${fn:replace(subFeatureName , '\'', '\\\')}"/>
试试