JSP中的子字符串函数在警告功能中不起作用。

huangapple go评论58阅读模式
英文:

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?

&lt;%@ include file=&quot;includes.jsp&quot;%&gt;
&lt;script src=&quot;js/bootstrap-datepicker.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;css/bootstrap-datepicker.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script src=&quot;js/jquery.dataTables.min.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;css/jquery.dataTables.min.css&quot; rel=&quot;stylesheet&quot; /&gt;
...
...
$(&quot;input[name=rnrInd]&quot;).change(
							function() {
								if ($(this).is(&quot;:checked&quot;)) {
									alert(${fn:substring(&quot;abcxyz&quot;, -1,3)});
									$(&quot;input[name=mnpCustName]&quot;).val(&quot;PREPAID SIM&quot;);
									$(&quot;input[name=mnpCustName]&quot;).attr(&quot;readonly&quot;, false);
									$(&quot;input[name=prepaidSimInd]&quot;).prop(&quot;checked&quot;, false) ;
								} else {
									//$(&quot;input[name=prepaidSimInd]&quot;).prop(&quot;checked&quot;, 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(&quot;abcxyz&quot;.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(&#39;${fn:substring(&quot;abcxyz&quot;, -1,3)}&#39;);

huangapple
  • 本文由 发表于 2023年2月8日 17:11:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383461.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定