1 為什么ie9不能執(zhí)行javascript,但是打開控制臺(tái)刷新頁面之后就可以?
IE8 與IE9 的console對象只有在打開了bug窗口之后才會(huì)被創(chuàng)建。之后的版本才解決了這個(gè)問題。
知道問題所在后,那就好解決了。
當(dāng)然了,我們可以刪掉這些console代碼,反正都是調(diào)試的
不過,如果太多的話,我們可以重寫console對象以及它的方法,這樣的話js就不會(huì)出錯(cuò)了
<script type="text/javascript">
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});
while (length--) {
method = methods[length];
if (!console[method]) {
console[method] = noop;
}
}
}());
</script>