英文:
Substring function in JSP does not respond in an alert function
问题
以下是翻译好的部分:
这段代码没有显示 "abc" 的警报,但没有任何错误消息?有什么解决方法吗?
<%@ include file="includes.jsp"%>
...
...
$("input[name=rnrInd]").change(
function() {
if ($(this).is(":checked")) {
alert(${fn:substring("abcxyz", -1, 3)});
$("input[name=mnpCustName]").val("PREPAID SIM");
$("input[name=mnpCustName]").attr("readonly", false);
$("input[name=prepaidSimInd]").prop("checked", false);
} else {
//$("input[name=prepaidSimInd]").prop("checked", false);
}
}).change();
英文:
The following code does not show the alert of "abc" but there is no any error message? Any idea to solve it?
<%@ include file="includes.jsp"%>
<script src="js/bootstrap-datepicker.js"></script>
<link href="css/bootstrap-datepicker.css" rel="stylesheet" />
<script src="js/jquery.dataTables.min.js"></script>
<link href="css/jquery.dataTables.min.css" rel="stylesheet" />
...
...
$("input[name=rnrInd]").change(
function() {
if ($(this).is(":checked")) {
alert(${fn:substring("abcxyz", -1,3)});
$("input[name=mnpCustName]").val("PREPAID SIM");
$("input[name=mnpCustName]").attr("readonly", false);
$("input[name=prepaidSimInd]").prop("checked", false) ;
} else {
//$("input[name=prepaidSimInd]").prop("checked", false) ;
}
}).change();
答案1
得分: 1
You can use JavaScript substring()
function instead.
alert("abcxyz".substring(0, 3));
The JS code is evaluated when JSP have already been rendered. The alert()
function expects the argument of type string that could be printed in the dialog, but instead it is looking for variable abc
which is not available in the code. If you still want to call JSP function on the server, then a better approach is to add quotes to the returned value.
alert('${fn:substring("abcxyz", -1, 3)}');
英文:
You can use JavaScript substring()
function instead.
alert("abcxyz".substring(0, 3));
The JS code is evaluated when JSP have already been rendered. The alert()
function expects the argument of type string that could be printed in the dialog, but instead it is looking for variable abc
which is not available in the code. If you still want to call JSP function on the server then a better approach is to add quotes to returned value.
alert('${fn:substring("abcxyz", -1,3)}');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论