在我的JSP中,我根據JSTL的值調用JSP函數。我看到JS(內部JSTL)中的alert語句正在工作,但不是JQuery。這是爲什麼?爲什麼JSTL中的JS/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中的那個點之後出現*,那麼它將不起作用,因爲您的代碼不會找到該元素。 – Pointy