<script type="text/javascript">
// JS实现选项卡切换
var li=document.getElementsByTagName("li");
var div=document.getElementsByTagName("div");
function load()
{
li[0].className="change";
}
for(var i=0;i<li.length;i++)
{
li[i].onclick = function() {
for(var i = 0; i < li.length; i++) {
li[i].className = "";
}
li[i].className = "change";
for(var j = 0; j <div.length; j++) {
div[j].style.display="none";
}
div[i].style.display="block";
}
}
</script>
li[i].onclick = function() { for(var i = 0; i < li.length; i++) { li[i].className = ""; } // 把这个 li[i] 改成this 试试 li[i].className = "change"; for(var j = 0; j <div.length; j++) { div[j].style.display="none"; } div[i].style.display="block"; }
把onclick回调中的所有li[i] 改成 this