简体   繁体   English

转义双引号

[英]Escaping double quotes

I have this code snippet - 我有这个代码片段-

function updateUserSettings() {
    var cat;
    <logic:iterate id="category" name="studyData" property="categories">
        cat = dojo.byId("<%=category%>");
    </logic:iterate>
    ........
    ........
}

I want to escape double quote in <%=category%> value, but I can't use tag to do that. 我想在<%=category%>值中转义双引号,但是我不能使用标签来做到这一点。

Is there any other way I can achieve this? 我还有其他方法可以实现这一目标吗?

Try to avoid Scriptlet and use JSTL or expression like ${category} 尽量避免使用Scriptlet,并使用JSTL或${category}表达式

You don't need to escape double quote use single quote around it like 您不需要转义双引号就可以像这样使用单引号

cat = dojo.byId('${category}');

because JavaScript supports both double and single quotes for string. 因为JavaScript支持字符串的双引号和单引号。


EDIT: 编辑:

You can use JSTL fn:replace() Function to replace all occurrences of a string with another string. 您可以使用JSTL fn:replace() Function用另一个字符串替换所有出现的字符串。

For example: 例如:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
...

<c:set var="string1" value="This is first String."/>
<c:set var="string2" value="${fn:replace(string1,'first', 'second')}"/>

<p>Final String : ${string2}</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM