次のコードはFireFox 7で完全に機能しますが、IE 9で同じページをプルアップするとjQuery関数(非表示と表示)は機能しません。しかし、IEでデバッガを開いてリフレッシュすると、すべて正常に動作します。デバッガが動作していなくても、jQueryコードが動作しない場合は、デバッガをオンにしてIEを起動するとデバッグが困難になります。デバッガが動作していない限り、javacriptは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(){}; 'は問題を解決します。 –
@ user1265146 IE 9用ソリューションを使用する – Barun