爲什麼以下工作適用於onLoad,而不是onClick,以及解決方案是什麼? 在此先感謝...javascript setAttribute'className'在onLoad上工作,但不在onClick
<head>
<title>Untitled Page</title>
<LINK href=CSS/showdetails.css type=text/css rel=stylesheet />
</head>
<body OnLoad="javascript:showdetails()">
<script language=JavaScript src=js/showdetails.js type=text/javascript></script>
<div id="divResults" style="OVERFLOW: auto; HEIGHT: 480px;">
<span id="ShowResults" style="VISIBILITY: hidden">Display Results</span>
<p><input id="Button1" type="button" value="button" /></p>
</div>
<script type="text/javascript">
var btn = document.getElementById('Button1');
btn.onclick = function() {showdetails();};
function showdetails() {
var xc = document.getElementById('ShowResults');
var top_ul = document.createElement('ul');
top_ul.setAttribute('className','detclass');
var li1 = document.createElement('li');
li1.appendChild(document.createTextNode('craig'));
var ul2 = document.createElement('ul');
var li2 = document.createElement('li');
li2.appendChild(document.createTextNode('Mike'));
ul2.appendChild(li2);
li1.appendChild(ul2);
top_ul.appendChild(li1);
xc.appendChild(top_ul);
var vis = "visible";
xc.style.visibility = vis;
}
</script>
</body>
</html>
請下次使用代碼標籤,閱讀起來要容易得多。 – onigunn 2010-09-02 20:39:06
將腳本放在底部,就在