赞
踩
写了一个extjs页面,在chrome下调试好好的,在ie8下调试页面打开,进度条没按预期更新。代码如下:
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>ExtJs</title>
- <meta charset="GBK">
- <link href="ExtJs/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="ExtJs/ext-base.js"></script>
- <script type="text/javascript" src="ExtJs/ext-all-debug-w-comments.js"></script>
-
- </head>
- <body>
- <div>
- <script type="text/javascript">
-
- Ext.MessageBox.show({
- title: '倒计时提醒',
- <span style="white-space:pre"> </span> msg: '这是一个倒计时',
- buttons:{"ok":"知道了"},
- animEl: 'mb9',
- closable : false,
- width : 300,
- progress : true,
- progressText: '5秒后将xxx',
- fn: answerPhone
- });
-
- var timeLeft = 5;
- var countDownTask = {
- run:countDownFunc,
- interval:1000
- };
- function countDownFunc(){
- console.log("fuck" + timeLeft);
- if(timeLeft <= 0){
- Ext.MessageBox.updateProgress(1, "倒计时结束");
- Ext.MessageBox.buttons = false;
- //简单延迟后关闭窗口
- setTimeout(function(){Ext.MessageBox.hide()}, 500);
- //终止轮询任务
- Ext.TaskMgr.stop(countDownTask);
- answerPhone();
- }
- else{
- timeLeft--;
- Ext.MessageBox.updateProgress((5-timeLeft)/5, timeLeft+'秒之后将xxxx');
- }
- }
- Ext.TaskMgr.start(countDownTask);
-
- var answerPhone = function(){
- console.log("倒计时后调用的函数。");
- };
-
- </script>
- </div>
- </body>
- </html>

按F12查看控制台信息,发现这么一句"console未定义"。网上查了一下,有两种解决办法
1.注释掉console的语句(好暴力....)
2.但是有时候实在是需要支持console来调试,那么可以加入如下代码
- window.console = window.console || (function(){
- var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
- = c.clear = c.exception = c.trace = c.assert = function(){};
- return c;
- })();
加入上述片段后,ie8就可以使用console了,修改后的代码
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>ExtJs</title>
- <meta charset="GBK">
- <link href="ExtJs/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="ExtJs/ext-base.js"></script>
- <script type="text/javascript" src="ExtJs/ext-all-debug-w-comments.js"></script>
-
- </head>
- <body>
- <div>
- <script type="text/javascript">
- window.console = window.console || (function(){
- var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
- = c.clear = c.exception = c.trace = c.assert = function(){};
- return c;
- })();
-
- Ext.MessageBox.show({
- title: '倒计时提醒',
- msg: '这是一个倒计时',
- buttons:{"ok":"知道了"},
- animEl: 'mb9',
- closable : false,
- width : 300,
- progress : true,
- progressText: '5秒后将xxx',
- fn: answerPhone
- });
-
- var timeLeft = 5;
- var countDownTask = {
- run:countDownFunc,
- interval:1000
- };
- function countDownFunc(){
- console.log("fuck" + timeLeft);
- if(timeLeft <= 0){
- Ext.MessageBox.updateProgress(1, "倒计时结束");
- Ext.MessageBox.buttons = false;
- //简单延迟后关闭窗口
- setTimeout(function(){Ext.MessageBox.hide()}, 500);
- //终止轮询任务
- Ext.TaskMgr.stop(countDownTask);
- answerPhone();
- }
- else{
- timeLeft--;
- Ext.MessageBox.updateProgress((5-timeLeft)/5, timeLeft+'秒之后将xxxx');
- }
- }
- Ext.TaskMgr.start(countDownTask);
-
- var answerPhone = function(){
- console.log("倒计时后调用的函数。");
- };
-
- </script>
- </div>
- </body>
- </html>

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。