<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>
</head>
<body>
<ul>
<li>11</li>
<li>22</li>
<li id="li1">33</li>
<li>44</li>
<li>55</li>
</ul>
<script>
window.onload=function(){
var oLi=document.getElementById('li1');
var prev=oLi.previousElementSibling||oLi.previousSibling;//oLi.previousElementSibling与oLi.previousSibling位置不能颠倒,颠倒之后在火狐和chrome下会出错
prev.style.background='red';
}
</script>
</body>
</html>
//同理 firstChild、 lastChild、nextSibing兼容性问题解决方法一样