我有一个由几个jsp文件组成的Web应用程序,其中一些使用常见的jscript模块。我的问题是我在IE8中的jscript模块之间访问公共数据时遇到了困难。
例如 - 在jsp文件中:
<script for="window" event="onload">
// My globals.
myGlobals = new Object();
// Attach it to the window for maximum availability.
window.myGlobals = myGlobals;
// Add some fields to it.
// List is actually built from external data so cannot be included from external file.
myGlobals.filters = [
'Filter-Women',
'Filter-Men',
'Filter-Girls',
'Filter-Boys',
];
myGlobals.filtered = '';
</script>
并在一个单独的js文件中:
function filter(f) {
for (var i = 0;i < myGlobals.filters.length;i++){
if ( 'Filter-'+f == myGlobals.filters[i] ) {
filterIn(document.getElementById(myGlobals.filters[i]));
} else {
filterOut(document.getElementById(myGlobals.filters[i]));
}
}
myGlobals.filtered = f;
}
function filterIn(e) {
e.classList.add('filterselected');
}
function filterOut(e) {
e.classList.remove('filterselected');
}
在我的jsp中 - 该列表也是根据上述相同的外部数据构建的:
<div class="filterbuttons">
<a id="Filter-Women" onclick="filter('Women')">WOMEN</a>
<a id="Filter-Men" onclick="filter('Men')">MEN</a>
<a id="Filter-Girls" onclick="filter('Girls')">GIRLS</a>
<a id="Filter-Boys" onclick="filter('Boys')">BOYS</a>
</div>
现在这一切在Firefox中运行良好,但客户也需要在IE8中运行。在那里,myGlobals结构不可用,甚至不在窗口。有什么想法吗?
答案 0 :(得分:0)
问题解决了!
变化:
<script for="window" event="onload">
只是简单地说:
<script>
一切正常。