<script language="javascript">
function bianya()
{
alert(document.getElementById('a').innerHTML.toString()=="a")
alert(document.getElementById('a').innerHTML.toString()=="a")
if(document.getElementById('a').innerHTML=="a"){//这里去掉分号 ,加上大括号
document.getElementById('a').innerHTML="b";
}
}
</script>
<span id="a" onclick="bianya()" style="cursor:hand;" >a</span>//注意这里 ,你的a后面有个空格

解决方案 »

  1.   

    if(document.getElementById('a').innerHTML=="a";) 多了一个分号
    if(document.getElementById('a').innerHTML=="a") 
    <span id="a" onClick="bianya()" style="cursor:hand;" >a </span>
    多了一个空格
    <span id="a" onClick="bianya()" style="cursor:hand;" >a</span>  
      

  2.   

    顺便建议下我该看些什么方面的教材了 
    到网上下一个JAVASCRIPT方面的书看看。
      

  3.   


    DHTML.chm  网上有
      

  4.   

    书?
    http://bbs.51js.com/thread-74643-1-1.html
      

  5.   

    嘿嘿 确实多了个分号
    其实我想说的是下面段代码
    别的都可以不看 就看红色的
    不要红色的是对的  要红色的就报错<style type="text/css"> 
    body{ 
    font:12px; 

    .a{ 
    position:absolute; 
    top:30px; 
    left:0px; 
    width:200px; 
    height:150px; 
    background-color:#ffffff; 
    border-left:1px solid #A8C29F; 
    border-bottom:1px solid #A8C29F; 
    border-right:1px solid #A8C29F; 

    </style> 
    <script language="JavaScript" type="text/javascript"> function xianyin(){
    if(document.getElementById('oDiv').style.display=="")
    document.getElementById('oDiv').style.display="none";
    document.getElementById('s').innerHTML="□";else
    document.getElementById('oDiv').style.display="";
    document.getElementById('s').innerHTML="-";}
    var dragapproved=false; function drag() 

        if(!document.all) 
        { 
            return; 
        } 
        if(event.srcElement.className=="myClass") 
        { 
            dragapproved=true; 
            var obj=event.srcElement; 
            var tempX=obj.style.pixelLeft; 
            var tempY=obj.style.pixelTop; 
            var x=event.clientX; 
            var y=event.clientY; 
            document.onmousemove=move; 
            function move() 
            {           if(event.button==1 && dragapproved) 
              { 
        
                  obj.style.pixelLeft=tempX+event.clientX-x; 
                  obj.style.pixelTop=tempY+event.clientY-y; 
                  return false; 
              } 
            } 
        } 

    document.onmousedown=drag; 
    document.onmouseup=new Function("dragapproved=false"); 
    </script> 
    <div class="myClass" style="cursor:hand; position:absolute;top:200px;left:200px;width:200px; height:30px; background-color:#A8C29F;" onmouseover="this.style.cursor='hand';this.style.backgroundColor='#cccccc';" ondblclick="xianyin()" onmouseout="this.style.backgroundColor='#A8C29F';" >最新消息<span id="s" onclick="xianyin()">-</span> X
    <div id="oDiv" class="a" > <span class="b" >新浪 </span> </div>
      

  6.   

    if(){
    }else{
    }
    注意一般的写法