<html>
  <head>
    <title>更改链接</title>
  </head>
  
  <body>  <form>   
      <input id = "txt_cap01" type="text" value="">
      <input id = "txt_ref01" type="text" value="http://www.baidu.com">
      <input type="button" id="btn_add" value="添加链接">   
      <p> </p>
  </form>  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
  <script type="text/javascript">         $(document).ready(
              function(){  
                  $("#btn_add").click(
                         function(){  
                var ref_add = document.getElementById("txt_ref01").value
                var cap_add = document.getElementById("txt_cap01").value
                   $("p").after("<a href = '" + ref_add + "'>" + cap_add + "</a> <br>");   
                         }
                  ); 
             }
         );   </script>
  </body>
</html>
怎么改都可以,改的方法很多,而且貌似没必要ajax

解决方案 »

  1.   


    <html>
      <head>
        <title>更改链接</title>
      </head>
      
      <body>  <form>   
          <input id = "txt_cap01" type="text" value="">
          <input id = "txt_ref01" type="text" value="http://www.baidu.com">
          <input type="button" id="btn_add" value="添加链接">   
      </form>  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
      <script type="text/javascript">         $(document).ready(
                  function(){  
                      $("#btn_add").click(
                             function(){  
                    var ref_add = document.getElementById("txt_ref01").value
                    var cap_add = document.getElementById("txt_cap01").value
                       $("#btn_add").after("<br><a href = '" + ref_add + "'>" + cap_add + "</a> ");   
                             }
                      ); 
                 }
             );   </script>
      </body>
    </html>
    这样稍微好点,刚才看错了。
      

  2.   

    document.write()
    会覆盖页面中所有的内容。不能乱用。