<!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=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function onMouseDown()
{
   document.getElementById("aaa").href="http://www.google.com";
}
</script>
</head><body>
<a href="#" id="aaa">aaaaaaaaaaaaaa</div><br/>
<input type="button" onmousedown="onMouseDown()">
</body>
</html>按理说,按下按钮后,仅仅改变了<a>标签的href属性
但是现在的实际情况是:按下按钮后,页面转到谷歌首页why???????????你们可以试试

解决方案 »

  1.   

    <a href="#" id="aaa">aaaaaaaaaaaaaa</a>
      

  2.   

    <!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=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function onMouseDown()
    {
      document.getElementById("aaa").href="http://www.google.com";
    }
    </script>
    </head><body>
    <div>
    <a href="#" id="aaa">aaaaaaaaaaaaaa</a>
    </div>
    <input type="button" onmousedown="onMouseDown()">
    </body>
    </html>