“>”的奇怪问题和“<”被转换为“<”和“>>”在我的 jsf 应用程序中的 javascript 中
我有一些 javascript 试图在 jsf 应用程序中使用。我已经缩小了范围,这样如果我取出下面的行,一切都会正常,但是当我输入这些行时,我会在 chrome 控制台中收到一个错误,显示“意外;”它显示第一行为 if(maxdays > 1000) {
为什么它将大于符号转换为 >
?
if(maxdays > 1000) {
maxdays = 1000;
}
编辑: 这是整个 JSF 页面。
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:head>
<title>Protocol Dashboard</title>
<link type="text/css" rel="stylesheet" href="../css/styles.css" />
<script type="text/javascript" src="../js/jquery-1.5.2.js"></script>
<script type="text/javascript" src="../js/highcharts.src.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
//var chartData;
//var goodData;
var chart;
var studyType;
var categories;
var maxdays;
//var chart = new Highcharts.Chart({
var options = {
chart : {
renderTo : 'container',
type : 'bar'
},
title : {
text : 'Gantt module development plan'
},
subtitle: {
text: studyType
},
xAxis : {
categories : [ 'Planning', 'Development',
'Testing', 'Documentation' ]
},
yAxis : {
type : 'datetime',
min : Date.UTC(2012, 0, 1),
labels : {
formatter : function() {
return Highcharts.dateFormat('%m/%d/%Y',
this.value);
}
}
},
tooltip : {
formatter : function() {
var point = this.point;
return '<b>'
+ point.category
+ '</b><br/>'
+ Highcharts.dateFormat('%b %e, %Y',
point.low)
+ ' - '
+ Highcharts.dateFormat('%b %e, %Y',
point.y);
}
},
series : [ {
data : [ {
low : Date.UTC(2012, 0, 1),
y : Date.UTC(2012, 0, 15)
}, {
low : Date.UTC(2012, 0, 10),
y : Date.UTC(2012, 4, 28)
}, {
low : Date.UTC(2012, 3, 15),
y : Date.UTC(2012, 4, 28)
}, {
low : Date.UTC(2012, 4, 15),
y : Date.UTC(2012, 4, 28)
} ]
}, {
data : [ {
low : Date.UTC(2012, 0, 1),
y : Date.UTC(2012, 1, 15)
}, {
low : Date.UTC(2012, 0, 10),
y : Date.UTC(2012, 3, 15)
}, {
low : Date.UTC(2012, 3, 15),
y : Date.UTC(2012, 6, 14)
}, {
low : Date.UTC(2012, 4, 15),
y : Date.UTC(2012, 4, 25)
} ]
} ]
};
function loadData() {
//options.series.length = 0;
//options.xAxis.categories.length = 0;
$('#hiddenData').val('09-034,99|10-053,194');
$('#hiddenCategories').val('09-034|10-053');
$('#clickedMenu').val('P2C');
$('#hiddenMaxDays').val('194');
var chartData = $('#hiddenData').val();
console.log('hiddenData = '+chartData);
categories = $('#hiddenCategories').val();
console.log('hiddenCategories = '+categories);
studyType = $('#clickedMenu').val();
console.log('clickedMenu = '+studyType);
maxdays = $('#hiddenMaxDays').val();
console.log('hiddenMaxDays = '+maxdays);
console.log('maxdays = '+maxdays);
//options.yAxis.max = maxdays;
options.subtitle.text = studyType;
var goodData = chartData.split('|');
//console.log('goodData = '+goodData);
//var goodCategories = categories.split(",");
//console.log('goodCategories = '+goodCategories);
/*
var series = {
data : []
};
var cat = {
categories : []
};
try {
$.each(goodData, function(index, value) {
var goodData2 = value.split(",");
//series.name = goodData2[0];
series.data.push(parseFloat(goodData2[1]));
});
$.each(goodCategories, function(index, value) {
var prot = value;
options.xAxis.categories.push(value);
});
options.series.push(series);
//console.log(options);
} catch (err) {
//console.log("ERROR ..." + err.description + ' message:'
//+ err.message);
}*/
}
function loadDataAndCreateChart() {
loadData();
//console.log(options);
chart = new Highcharts.Chart(options);
}
loadDataAndCreateChart();
});
</script>
</h:head>
<h:body>
<div id="container"></div>
<h:inputHidden value="#{selectCategory.jsonResults }" id="hiddenData" />
<h:inputHidden value="#{selectCategory.jsonResultsCategories }" id="hiddenCategories" />
<h:inputHidden value="#{selectCategory.menuItem}" id="clickedMenu" />
<h:inputHidden value="#{selectCategory.maxDays}" id="hiddenMaxDays" />
</h:body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用 Facelets,这是一种基于 XML 的视图技术。 JavaScript 运算符如
>
、&
等是我强烈建议将所有 JS 代码放在自己的
.js
文件中,并通过或
。例如
或
其他优点是,您可以通过这种方式微调浏览器缓存,并最终获得更高效服务的网站。
与具体问题无关:请注意我如何引用这些库。您应该更喜欢域相对路径而不是 URI 相对路径。使用
../
是一种维护上的痛苦。如果您移动视图或更改请求 URI,它就会中断。You're using Facelets, which is a XML based view technology. JavaScript operators like
>
,&
, etc are special characters in XML and are illegal when used for other purposes inside a XML file. Facelets is taking care of them this way.I strongly recommend to put all that JS code in its own
.js
file and reference it by a<script src>
or a<h:outputScript>
.E.g.
or
Additional advantage is that you can finetune browser caching this way and end up in a more efficiently served website.
Unrelated to the concrete problem: please note how I referenced the libraries. You should prefer domain-relative paths over URI-relative paths. Using
../
is a maintenance pain. If you move the view or change the request URI, it'll break.>
是 HTML 实体,必须用于输出 HTML 中的>
字符。<
和>
是 HTML 标记使用的特殊字符,因此必须转义为<
和& gt;
如果这些字符必须显示在页面中。我怀疑您正在使用转义其输入的 JSF 标记。我对 JSF 没有太多经验,但您可能会尝试将脚本包含在 CDATA 部分中:
但最好的解决方案是根本不在 HTML 中使用 JavaScript,而是从外部文件加载它。
>
is the HTML entity which must be used to output the>
character in HTML.<
and>
are special characters used by the HTML markup and must thus be escaped to<
and>
if these characters must be displayed in the page. I suspect you're using a JSF tag which escapes its input.I don't have much experience with JSF, but you might try to enclose the script in a CDATA section:
But the best solution is not to have JavaScript in HTML at all, and load it from an external file.