JavaScript代码:common.js
function setFocus(evt,data)
{
var keycode=evt.keyCode;
$("[tabindex="+data[keycode]+"]").focus();
return false;
}
PHP代码:
<table class="tblmenu">
<tr>
<td><div class="redbut"><a href="#" id="formstng" tabindex="1" onKeyPress="setFocus(event,{'38':'5','40':'2'})">foT Aosa.Aona.Aof. laokTao saoTIMga </a></div></li></td>
</tr>
<tr>
<td><div class="redbut"><a href="#" id="setting" tabindex="2" onKeyPress="setFocus(event,{'38':'1','40':'3'})">roT saoTIMga</a></div></td>
</tr>
<tr>
<td><div class="redbut"><a href="#" tabindex="3" onKeyPress="setFocus(event,{'38':'2','40':'4'})">slaIpa saoTIMga</a></div></td>
</tr>
<tr>
<td><div class="redbut"><a href="#" tabindex="4" onKeyPress="setFocus(event,{'38':'3','40':'5'})">isasTma saoTIMga</a></div></td>
</tr>
<tr>
<td><div class="redbut"><a href="#" tabindex="5" onKeyPress="setFocus(event,{'38':'4','40':'1'})">yauzr AonT/I</a></div></td>
</tr>
</table>
我试着把重点放在箭头键的链接上。这在firefox中运行良好但在chrome中运行不正常 和IE。 在此先感谢..
答案 0 :(得分:4)
请使用evt.charCode代替evt.keyCode for IE,(即)你可以使用如下,
var keycode = evt.keyCode? evt.keyCode : evt.charCode