当我点击一个链接时,我正在尝试调用一个JavaScript函数。这个JavaScript函数是在JSP的属性中定义的,我正在尝试将一个scriptlet变量传递给函数。然而,它没有得到评估。守则的有关部分是:
<span>
<mysecurity:secure_link id='<%="editButton_"+commentUUID%>' entitlement=""
actionOnClick="editComment('<%= commentUUID %>');return false;"
isSurroundedByBrackets="true" enableTitle="" disableLink="<%=disableLink%>">
<span style="color:#0033BB; font:8pt arial;">
<bean:message key="button.edit" />
</span>
</mysecurity:secure_link>
</span>IE8在左下角提到一个JavaScript错误。当我右键单击并查看源代码时,生成的HTML是:
onclick="editComment('<%= commentUUID %>');return false;"因此,<%=commentUUID%>不是在actionOnClick属性中计算的,而是在id属性中成功地计算出来的。
这是怎么引起的,我怎么解决呢?
发布于 2011-08-10 17:08:39
在@BalusC的建议下,最终对我有用的是使用社论(this.id.split(‘_’)1)。正确的工作代码如下:
<span>
<mysecurity:secure_link id='<%="editButton_"+commentUUID%>' entitlement=""
actionOnClick="javascript:editComment(this.id.split('_')[1]);return false;"
isSurroundedByBrackets="true" enableTitle="" disableLink="<%=disableLink%>">
<span style="color:#0033BB; font:8pt arial;">
<bean:message key="button.edit" />
</span>
</mysecurity:secure_link>
</span>发布于 2011-08-09 20:23:10
我不确定<mysecurity:secure_link>是自定义的还是现有的第三方JSP标记库。现代JSP标记通常不计算遗留的scriptlet表达式。您应该更愿意使用EL (Expression Language)。
首先,确保commentUUID变量作为页面或请求作用域的属性存储,以便EL可以使用它,如下所示,在预处理servlet中
request.setAttribute("commentUUID", commentUUID);或者在JSP中使用另一个脚本:
<% request.setAttribute("commentUUID", commentUUID); %>或者在JSP中使用JSTL的<c:set>:
<c:set var="commentUUID"><%=commentUUID%></c:set>然后,您可以使用EL访问它,如下所示:
<mysecurity:secure_link actionOnClick="editComment('${commentUUID}');return false;" />https://stackoverflow.com/questions/7002033
复制相似问题