다음 코드는 FireFox 7에서 완벽하게 작동하지만 IE 9에서 동일한 페이지를 가져올 때 jQuery 함수 (숨기기 및 표시)가 작동하지 않습니다. 그러나 IE에서 디버거를 열고 새로 고치면 모든 것이 잘 작동합니다. 디버거가 실행 중이고 페이지를 새로 고침 (또는 디버거를 켜고 IE를 시작)하지 않으면 jQuery 코드가 작동하지 않는 것처럼 보이므로 분명히 디버깅하기가 어렵습니다.디버거가 실행되고 있지 않으면 JavaScript가 IE에서 작동하지 않습니다.
이 샘플에는 모든 CSS와 스크립팅이 포함되어 있습니다. 다른 정보가 필요하면 알려주십시오.
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<!--<link href="_css/main.css" rel="stylesheet" type="text/css" />-->
<style>
html, body {
margin: 0px;
padding: 0px;
}
#wrapper {
width:1000px;
margin-left: auto;
margin-right: auto;
height: 100%;
}
#sidebar {
width: 100px;
height:100%;
float: left;
background-color: #FF0;
}
#maincontent {
float: left;
width: 400px;
height:100%;
;
background: #c1d8b9;
}
#right {
width: 500px;
background-color: #0F3;
float: right;
height: 100%;
}
body {
background-color: white;
}
ul
{
list-style-type: none;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="wrapper">
<div id="sidebar"> Sidebar
<ul >
</ul>
</div>
<div id="maincontent"> Main content
<button id="hidr">Hide</button>
<button id="showr">Show</button>
<ul id="listMiddle">
<li id="li1">TEST1</li>
<li id="li2">TEST2</li>
<li id="li3">TEST3</li>
<li id="li4">TEST4</li>
</ul>
</div>
<div id="right"> Right
<ul id="listRight">
</ul>
</div>
</div>
<script>
var arryLIs = document.getElementsByTagName('li');
var middleUL = document.getElementById('listMiddle');
var rightUL = document.getElementById('listRight');
var arrymiddleLIs = middleUL.getElementsByTagName('li');
var arryrightLIs = rightUL.getElementsByTagName('li');
for (var i=0; i<arryLIs.length; i++){
arryLIs[i].onclick = moveright;
//console.log(arryLIs[i].innerHTML);
}
console.log(arrymiddleLIs);
console.log(middleUL);
var goBefore=null;
function moveright() {
var goBefore=null;
goBefore=findSortRight(this);
document.getElementById('listRight').insertBefore(this,goBefore);
this.onclick = moveleft;
//console.log(arrymiddleLIs);
//console.log(arryrightLIs);
}
function moveleft() {
document.getElementById('listMiddle').appendChild(this);
this.onclick = moveright;
console.log(arrymiddleLIs);
console.log(arryrightLIs);
}
function findSortRight(newElement){
var goBefore=null;
for (var r=0; r<arryrightLIs.length; r++){
//console.log(newElement.innerHTML<=arryrightLIs[r].innerHTML);
if (newElement.innerHTML<=arryrightLIs[r].innerHTML) {
//console.log(arryrightLIs[r]);
goBefore=arryrightLIs[r];
break;
}
}
// console.log(goBefore.innerHTML);
return goBefore;
}
$("#hidr").click(function() {
$("li").hide();
});
$("#showr").click(function() {
$("li").show();
});
</script>
</body>
</html>
제거하면 문제가 해결됩니다! 디버거가 실행 중일 때 왜 제대로 작동하는지 설명합니다. 빠른 도움말 및 추가 정보를 보내 주셔서 감사합니다. – dangel
이렇게하면 적어도 Chrome에서는 console.log를 덮어 씁니다. 'console = console || {}; console.log = console.log || function() {};은 문제를 해결합니다. –
IE 9 용 @ user1265146 솔루션 사용 – Barun