日期:2014-05-16  浏览次数:20396 次

怎样让超链接响应回车啊?
我在一个网页上有几个文本框和一个超链接,当我单击回车时我想让超链接响应并执行相应操作,应该怎么实现呢?哪位高手能指点一二?谢谢啦!!!

------解决方案--------------------
<head>
<script language=javascript>

function document.onkeydown()
{
if (event.keyCode == 13)
{
//alert( "do what you want ");
location.href = document.getElementById( "ts ").href;
}
}
</script>
</head>
<BODY>
<FORM NAME= "f ">
<input type= "text " name= "test1 "> <br>
<input type= "text " name= "test1 "> <br>
<a href= "http://www.sina.com.cn " id= "ts "> www.sina.com.cn </a>
</FORM>
</BODY>
------解决方案--------------------
<script language= "javascript " type= "text/javascript ">

function document.onkeydown()
{
if (event.keyCode == 13)
{
window.location.href(document.getElementById( "ts ").href);
}
}
</script>
------解决方案--------------------
<!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>
</head>

<body>
<div onmousedown= "aa(this); ">
<a id= "a1 " href= "http://www.google.cn "> google </a>
<input type= "text " onkeydown= "aa(event); "/>

</div>

</body>
</html>
<script type= "text/javascript ">

function aa(evt)
{

evt = (evt) ? evt : ((window.event) ? window.event : " ")

if(evt.keyCode == 13)
{

window.location.href=document.getElementById( "a1 ").href;
}
}

//window.location.href(document.getElementById( "a1 ").href);
</script>


----
兼容各浏览器的