javascript extjs 和 Internet Explorer 8 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5343242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
problem with extjs and internet explorer 8
提问by Mansuro
I wrote a program with extjs library, the program works fine in all browsers, except internet explorer 8, the problem is, it works when i load it from localhost, but when accessed from the server, it doesn't load the page, i have a blank page,
I removed a comma and the program started working when accessed from the server. Does someone have an explanation?
我用 extjs 库编写了一个程序,该程序在所有浏览器中都可以正常工作,除了 Internet Explorer 8,问题是,当我从本地主机加载它时它可以工作,但是当从服务器访问时,它没有加载页面,我有一个空白页,
我删除了一个逗号,程序在从服务器访问时开始工作。有人有解释吗?
here is the header:
这是标题:
<!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" xml:lang="en" lang="en">
<head>
<meta name="Description" content="Default Style" />
<meta name="Version" content="2.1.1" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>project name</title>
<link rel="stylesheet" type="text/css" href="./style/default/main.css" media="all" />
<style type="text/css" media="all">@import "./style/default/main.css";</style>
<link rel="shortcut icon" href="./style/default/images/favicon.ico" type="image/ico" />
<script type="text/javascript" src="http://10.215.63.218/Apsys/js/base.js"></script>
<script type="text/javascript" src="http://10.215.63.218/app/js/collapse.js"></script>
<script type="text/javascript" src="http://10.215.63.218/app/lib/overlib/overlib.js"></script>
</head>
回答by Sean Adkinson
Internet Explorer can't handle trailing commas on objects and arrays. This becomes an especially recurring problem with Ext, where you regularly create large objects, one attribute per line, and comment/remove things a lot.
Internet Explorer 无法处理对象和数组的尾随逗号。这成为 Ext 的一个特别反复出现的问题,您可以定期创建大型对象,每行一个属性,并经常注释/删除内容。
This will break in IE:
这将在 IE 中中断:
new Ext.Panel({
id: 'mypanel',
cls: 'my-panel-class',
html: 'Some HTML',
colors: [
'yellow',
'blue',
'red',
//'pink'
],
renderTo: Ext.getBody(),
});
Notice the extra comma after 'red'
and Ext.getBody()
in the first block.
注意第一个块之后'red'
和Ext.getBody()
中的额外逗号。
This will work:
这将起作用:
new Ext.Panel({
id: 'mypanel',
cls: 'my-panel-class',
html: 'Some HTML',
colors: [
'yellow',
'blue',
'red'
//'pink'
],
myArray: ['yellow', 'blue', 'red'],
renderTo: Ext.getBody()
});
回答by Colin
For the difference between localhost vs your server, there is a setting in IE that forces internal websites into compatibility mode regardless of doctype. This would explain the difference between functionality if you have it set.
对于 localhost 与您的服务器之间的区别,IE 中有一个设置可以强制内部网站进入兼容模式,而不管 doctype。如果您设置了它,这将解释功能之间的区别。
Either way, you should keep the good syntax and not have trailing commas in arrays or objects.
无论哪种方式,您都应该保持良好的语法,并且不要在数组或对象中使用尾随逗号。
回答by AmorALess
Why Explorer works in localhost and not in a published server is a real mystery, but, check your HTML, my example runs correct in Chrome and Explorer 8 (in localhost) my error:
为什么 Explorer 在 localhost 而不是在已发布的服务器中工作是一个真正的谜,但是,检查您的 HTML,我的示例在 Chrome 和 Explorer 8(在 localhost)中运行正确,我的错误:
<body style="text-align:center">
<div id="bodyForm" style="width:100%;">
</div>
</body>
in app.js
在 app.js 中
renderTo: Ext.get('bodyForm')
I correct to:
我更正:
<body id="idBody">
</body>
in app.js:
在 app.js 中:
renderTo: Ext.get('idBody')