【发布时间】:2016-03-20 13:47:54
【问题描述】:
在我的 JSP 中,我根据 JSTL 的值调用了一个 JSP 函数。我看到 JS(在 JSTL 内部)中的警报语句正在工作,但不是 JQuery。这是为什么呢?
<c:set var = "error" value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>
<c:choose>
<c:when test="${error=='not unregistered'}">
<script type="text/javascript">
alert("Hi");
openSignUp();
</script>
</c:when>
<c:otherwise>
<c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
</c:otherwise>
</c:choose>
<c:remove var = "SPRING_SECURITY_LAST_EXCEPTION" scope = "session" />
<script>
function openSignUp(){
$('#signUp_dialog').dialog({
width:350,
open: function(event, ui) {
$(".ui-button-text").remove();
$(".ui-dialog-title").css("margin-right","275px");
}
});
}
</script>
我也尝试了以下方法,将代码直接放在 JS 函数中的 JSTL 脚本标记中。还是没有运气。
<c:set var = "error" value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>
<c:choose>
<c:when test="${error=='not unregistered'}">
<script type="text/javascript" src="<c:url value="/resources/scripts/jquery-ui-1.11.4/external/jquery/jquery.js" />">
$(document).ready(function() {
$('#signUp_dialog').dialog({
width:350,
open: function(event, ui) {
alert("hi");
$(".ui-button-text").remove();
$(".ui-dialog-title").css("margin-right","275px");
}
});
});
</script>
</c:when>
<c:otherwise>
<c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
</c:otherwise>
</c:choose>
<c:remove var = "SPRING_SECURITY_LAST_EXCEPTION" scope = "session" />
请帮助我。谢谢。
【问题讨论】:
-
如果 "signUp_dialog" 元素出现在 DOM 中 之后 的那个点,那么它就不起作用,因为您的代码找不到该元素。
标签: javascript jquery jsp spring-mvc jstl