在我的jsf应用程序中,在javascript中将“>”和“<”转换为“<”和“>”的奇怪问题
作者:互联网
我有一些javascript,我想在jsf应用程序中使用.我把它缩小了,所以如果我拿出下面的行,事情就可以了,但是当我有这些行时,我在chrome控制台中出现了一个错误,说“意外”;它显示第一行好像(maxdays& gt; 1000){
为什么将大于号码转换为& gt;?
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>
解决方法:
您正在使用Facelets,这是一种基于XML的视图技术.像>,&等等JavaScript运算符在XML中是special characters,在XML文件中用于其他目的时是非法的. Facelets以这种方式照顾他们.
我强烈建议将所有JS代码放在自己的.js文件中,并通过< script src>引用它.或者是<h:outputScript>
.
例如.
<script src="#{request.contextPath}/js/global.js"></script>
要么
<h:outputScript name="js/global.js" />
另外一个好处是,您可以通过这种方式微调浏览器缓存,最终获得更高效的服务网站.
与具体问题无关:请注意我是如何引用库的.您应该优先选择URI相对路径上的域相对路径.使用../是一种维持痛苦.如果您移动视图或更改请求URI,它将会中断.
标签:jquery,java,javascript,jsf,facelets 来源: https://codeday.me/bug/20190621/1254054.html