jsf/icefaces 中的 JavaScript
我有一个带有 jspx 扩展名的文件,我编写的 javascript
function isNumber(inputId){
var value = document.getElementById('mainForm:'+ inputId).value;
var s = value.length;
while(s >= 0){
var c = value.charAt(s);
if(c > "9"){
alert("Value must be digit");
document.getElementById('mainForm:'+ inputId).value = "";
document.getElementById('mainForm:'+ inputId).focus();
return false;
}
s --;
}
return true;
}
工作得很好,但是当我检查 if(c > "9" || c < "0") 这样的条件时,它会给出类似的错误
com.sun.facelets.FaceletException: Error Parsing /WEB-INF/includes/templates/cc-classic-template.jspx: Error Traced[line: 386] The content of elements must consist of well-formed character data or markup.
经过长时间观察,我发现 < (小于)符号会产生问题。 JSF不支持<符号 ?
I have file with jspx extension i write javascript like
function isNumber(inputId){
var value = document.getElementById('mainForm:'+ inputId).value;
var s = value.length;
while(s >= 0){
var c = value.charAt(s);
if(c > "9"){
alert("Value must be digit");
document.getElementById('mainForm:'+ inputId).value = "";
document.getElementById('mainForm:'+ inputId).focus();
return false;
}
s --;
}
return true;
}
that work perfect but when i check if condition like if(c > "9" || c < "0") it will gives error like
com.sun.facelets.FaceletException: Error Parsing /WEB-INF/includes/templates/cc-classic-template.jspx: Error Traced[line: 386] The content of elements must consist of well-formed character data or markup.
After long observation i found that <(less than) sign will create problem.
Is JSF not support < sign ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的 Javascript 包含在 CDATA 部分中:
Enclose your Javascript in CDATA Sections:
正如 Matt Handy 所解释的,您不能在 JSPX 中使用
<
或>
符号,因为这是 XML 格式。针对您的问题,您有以下三种解决方案:<
或>
进行转义。将 JavaScript 代码保存在页面中。
.js
文件中设置 JavaScript 代码,并将其加载到 JSPX 页面中。As explained by Matt Handy, you could not use the
<
or>
sign in your JSPX, as this is a XML format. You have three solutions regarding your problem:<
or>
.<![CDATA[ ... ]]>
to hold your JavaScript code in your page..js
file, and load it in your JSPX page.除了转义和 CDATA 答案之外:
如果你想检查一个值是否是数字,有一个 javascript 内置函数:
isNaN
下面是一个示例:
Besides the escaping and CDATA answers:
If you want to check if a value is a number, there is a javascript built-in function for that:
isNaN
Here is an example: