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,请使用 evt.charCode 而不是 evt.keyCode,(即)您可以按如下方式使用,
var keycode = evt.keyCode? evt.keyCode : evt.charCode
关于php - 我的 JavaScript 代码在 Firefox 中运行良好,但在 chrome 和 IE 中运行不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13833485/