解决方案 »

  1.   


    <html>
    <head>  
      <script type="text/javascript" >
        function changeName()
        {
          //alert("run here")
          var p1=document.getElementById('p1')
          p1.setAttribute('name',"p2")
          document.getElementsByName("p2")[0].innerHTML="hello,world!"
          //alert('here')
        }
      </script>
    </head>
    <body>
    <p id="p1" name="p1">Hello</p>
    <button onclick="changeName()">改变名字并输出</button></body>
    </html>
      

  2.   

    <html>
    <head>    
        <script type="text/javascript" />
            function changeName()
            {
                alert("run here")
                var p1=document.getElementById('p1')
                p1.setAttribute('name',"p2")
                document.getElementsByName("p2")[0].innerHTML="hello,world!"
                alert('here')
            }
        </script>
    getElementsByName在有些浏览器会有问题  最好不要用
    </head>
    <body>
    <p id="p1" name="p1">Hello</p>
    <button onclick="changeName()">改变名字并输出</button>
     
    </body>
    </html>