当前位置: 代码迷 >> ASP.NET >> 求:光标焦点在不同文本框时怎么改变默认回车按钮
  详细解决方案

求:光标焦点在不同文本框时怎么改变默认回车按钮

热度:4221   发布时间:2013-02-25 00:00:00.0
求:光标焦点在不同文本框时如何改变默认回车按钮?
如题:
假如有2个文本框   当光标焦点在不同文本框时   按回车后的默认按钮是不同的。
要如何实现?

------解决方案--------------------------------------------------------
参考onkeydown事件
------解决方案--------------------------------------------------------
<html>
<head>
<title> 测试 </title>
<script language= "javascript ">
function InputGo(v)
{
if( event.keyCode == 13 )
{
switch( parseInt(v) )
{
case 0:
document.getElementById( 'B_A ').click();
break;

case 1:
document.getElementById( 'B_B ').click();
break;
}
}
}
</script>
</head>
<body>
<input onkeydown= "InputGo(0) " /> <input onkeydown= "InputGo(1) " />
<button onclick= "alert( 'A '); " id= "B_A "> A </button> <button onclick= "alert( 'B '); " id= "B_B "> B </button>
</body>
</html>
  相关解决方案