//下面这段代码 <a……>中的 onclick 不会被执行
//我想实现的功能是,让执行链接的同时调用show()函数。应该怎样写?
<html>
<head>
<script type="text/javaScript">
function show()
{
  document.write("A function has been called when clicking the link");
}
</script>
</head><body><a href="http://www.sina.com.cn" onclick="show()"> http://www.sina.com.cn </a></body>
</html>

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">
    function show() {
    alert("test");
    location.href="http://www.sina.com.cn";
    }</script>
    </head>
    <body>
    <a href="#" onclick="show()"> http://www.sina.com.cn </a>
    </body>
    </html>
      

  2.   


    <html>
    <head>
    <script type="text/javaScript">
    function show()
    {
      document.write("A function has been called when clicking the link");
    }
    </script>
    </head><body><a href="http://www.sina.com.cn" onclick="show();" target="_blank"> http://www.sina.com.cn </a></body>
    </html>
    开在新窗口,这样才能看到在本document里write。
      

  3.   

    js是本页面执行的,链接是新页面,你先理清楚逻辑,到底是本页面打印js,跳出新页面,还是跳出新页面,然后在新页面执行打印
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">
        function show(strurl) {
            document.write("A function has been called when clicking the link");
    setTimeout(location.href=strurl,100);
        }</script>
    </head>
    <body>
    <a href="http://www.sina.com.cn" onClick="show(this.href)"> http://www.sina.com.cn </a>
    </body>
    </html>