按shift不好,这样会打开新窗口,这里按ctrl来<!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=gb2312">
<title>无标题文档</title>
<script>
function getIt(){
if (event.ctrlKey)
window.open("link1");
else
window.open("link2");
}
</script>
</head><body>
<a href="javascript:void(0)" onClick="getIt()">GET IT</a>
</body>
</html>

解决方案 »

  1.   

    谢谢!!!请教这个是什么意思"javascript:void(0)" 。 试了一下好像没有作用呢?我是jsp页面里写的!
      

  2.   

    如果在同一个页面打开呢???用location.href,好像没有用呢!!!但是用window.open("link");可以打开!!!<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title><script language="javascript">function getIt()
    {
    if (event.ctrlKey)
    {
    window.open("1.jsp");
    }
    else
    {
    window.open("2.jsp");
    }
    }</script></head><body>
    <form method="post">
    <a href="javascript:void(0)" onClick="getIt()">GET IT</a>
    </form>
    </body>
    </html>
      

  3.   

    以下是操作符void的定义:
    对一个指定的表达式进行求值而不返回任何值!也就是在这里它什么也不做
    但void有一个防止错误返回的作用