<!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>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
var myLinkItem=document.getElementById("linkedItem");
var first=firstSibling(myLinkItem.parentNode);
var last=lastSibling(myLinkItem.parentNode);
alert(getTextContent(first));
alert(getTextContent(last));
}
function lastSibling(node){
var temObj=node.parentNode.lastChild;
while(temObj.nodeType!=1 && temObj.previosSibling!=null){
tempObj=tempObj.previousSibling;
}
return (tempObj.nodeType==1)?tempObj:false;
}
function firstSibling(node){
var tempObj=node.parentNode.firstChild;
while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
tempObj=tempObj.nextSibling;
}
return (tempObj.nodeType==1)?tempObj:false;
}
function getTextContent(node){
return node.firstChild.nodeValue;
}
</script>
</head><body>
<ul id="eventsList">
<li>List Item 1</li>
    <li>List Item 2</li>
    <li>
     <a id="linkedItem" href="http://www.google.com/">Linked List Item</a>
    </li>
    <li>List Item 4</li>
</ul>
</body>
</html>

解决方案 »

  1.   

    拼写错误!!!
    function lastSibling(node){ 
    var temObj=node.parentNode.lastChild; 
    while(temObj.nodeType!=1 && temObj.previosSibling!=null){ 
    tempObj=tempObj.previousSibling; 
    } tem -> temp<!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>无标题文档 </title> 
    <script type="text/javascript"> 
    window.onload=function(){ 
    var myLinkItem=document.getElementById("linkedItem"); 
    var first=firstSibling(myLinkItem.parentNode); 
    var last=lastSibling(myLinkItem.parentNode); 
    alert(getTextContent(first)); 
    alert(getTextContent(last)); 
    };
    function lastSibling(node){ 
    var tempObj=node.parentNode.lastChild; 
    while(tempObj.nodeType!=1 && tempObj.previosSibling!=null){ 
    tempObj=tempObj.previousSibling; 

    return (tempObj.nodeType==1)?tempObj:false; 

    function firstSibling(node){ 
    var tempObj=node.parentNode.firstChild; 
    while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){ 
    tempObj=tempObj.nextSibling; 

    return (tempObj.nodeType==1)?tempObj:false; 

    function getTextContent(node){ 
    return node.firstChild.nodeValue; 

    </script> 
    </head> <body> 
    <ul id="eventsList"> 
    <li>List Item 1 </li> 
        <li>List Item 2 </li> 
        <li> 
    <a id="linkedItem" href="http://www.google.com/">Linked List Item </a> 
        </li> 
        <li>List Item 4 </li> 
    </ul> 
    </body> 
    </html>
      

  2.   

    拼写错误 previosSibling ->previousSibling
    temObj -> tempObj<!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>无标题文档 </title> 
    <script type="text/javascript"> 
    window.onload=function(){ 
    var myLinkItem=document.getElementById("linkedItem"); 
    var first=firstSibling(myLinkItem.parentNode); 
    var last=lastSibling(myLinkItem.parentNode); 
    alert(getTextContent(first)); 
    alert(getTextContent(last)); 

    function lastSibling(node){ 
    var tempObj=node.parentNode.lastChild; 
    while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){ 
    tempObj=tempObj.previousSibling; 
    }
    return (tempObj.nodeType==1)?tempObj:false; 

    function firstSibling(node){ 
    var tempObj=node.parentNode.firstChild; 
    while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){ 
    tempObj=tempObj.nextSibling; 

    return (tempObj.nodeType==1)?tempObj:false; 

    function getTextContent(node){ 
    return node.firstChild.nodeValue; 

    </script> 
    </head> <body> 
    <ul id="eventsList"> 
    <li>List Item 1 </li> 
        <li>List Item 2 </li> 
        <li> 
        <a id="linkedItem" href="http://www.google.com/">Linked List Item </a> 
        </li> 
        <li>List Item 4 </li> 
    </ul> 
    </body> 
    </html>