使用DOM改变链接

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>使用DOM改变链接</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  </head>
  <script type="text/javascript">
   var count = 0;
   function changeLink(){
      if((count += 1)%2 == 0){
       document.getElementById("taobao").innerHTML="搜狐";
       document.getElementById("taobao").href="http://www.sohu.com";
      }else{
       document.getElementById("taobao").innerHTML="淘宝";
       document.getElementById("taobao").href="http://www.taobao.com";
      }
   }
  </script>
  <body>
   <table>
    <tr>
     <td><a id="taobao"  href="http://www.taobao.com ">淘宝</a></td>
     <td><input type="button" onclick="changeLink()" value="使用DOM改变链接"/></td>
    </tr>
   </table>
  </body>
</html>

你可能感兴趣的:(dom)