特殊陈旧浏览器下的按键焦点控制
<body onload="init();" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<a id="link1" href="#" onMouseOver="onButtonFocus('link1');showName()">test1</a><br>
<a id="link2" href="#" onMouseOver="onButtonFocus('link2');showName()">test2</a><br>
<a id="link3" href="#" onMouseOver="onButtonFocus('link3');showName()">test3</a><br>
<a id="link4" href="#" onMouseOver="onButtonFocus('link4');showName()">test4</a><br>
<a id="link5" href="#" onMouseOver="onButtonFocus('link5');showName()">test5</a><br>
<a id="link6" href="#" onMouseOver="onButtonFocus('link6');showName()">test6</a><br>
<a id="link7" href="#" onMouseOver="onButtonFocus('link7');showName()">test7</a><br>
<a id="link8" href="#" onMouseOver="onButtonFocus('link8');showName()">test8</a><br>
<form id="form1" name="form1" action="#" method="get">
id <input name="show" type="text" size="10"><br>
key <input name="textfield" type="text" size="10"><br>
pc key <input name="pckey" type="text" size="10">
</form>
<script>
var currentButtonIndex = 0;
var currentButtonName = "";
var btnLinks = new Array();
</script>
<script>
function getButton(name)
{
for (var i = 0; i < btnLinks.length; i++ )
{
if(btnLinks[i]==name)
{
return i;
}
}
return 0;
}
function setFocus(name)
{
currentButtonIndex = getButton(name);
currentButtonName = name;
document.links[currentButtonIndex].focus();
}
</script>
<script>
function onButtonFocus(id)
{
currentButtonName = id;
currentButtonIndex = getButton(currentButtonName);
}
</script>
<script>
function showName()
{
document.form1.show.value=currentButtonIndex + " " + currentButtonName;
document.form1.textfield.value = currentButtonName;
}
function showKey(name)
{
document.form1.thekey.value=name;
}
</script>
<script>
btnLinks[0] = "link1";
btnLinks[1] = "link2";
btnLinks[2] = "link3";
btnLinks[3] = "link4";
btnLinks[4] = "link5";
btnLinks[5] = "link6";
btnLinks[6] = "link7";
btnLinks[7] = "link8";
</script>
<script>
function init()
{
setFocus("link8");
showName();
}
</script>
<script>
var key_up = 38;
var key_down = 40;
function doEvent(eventKey, key, srcId, focusId)
{
if(eventKey == key && currentButtonName==srcId)
{
setFocus(focusId);
}
}
function keyPress(keyval)
{
doEvent(keyval, key_up, "link8", "link7");
doEvent(keyval, key_down, "link7", "link8");
}
function keyEvent()
{
var val = event.keyCode.toString();
return keyPress(val);
}
document.onkeydown=keyEvent ;
</script>
</body>
<a id="link1" href="#" onMouseOver="onButtonFocus('link1');showName()">test1</a><br>
<a id="link2" href="#" onMouseOver="onButtonFocus('link2');showName()">test2</a><br>
<a id="link3" href="#" onMouseOver="onButtonFocus('link3');showName()">test3</a><br>
<a id="link4" href="#" onMouseOver="onButtonFocus('link4');showName()">test4</a><br>
<a id="link5" href="#" onMouseOver="onButtonFocus('link5');showName()">test5</a><br>
<a id="link6" href="#" onMouseOver="onButtonFocus('link6');showName()">test6</a><br>
<a id="link7" href="#" onMouseOver="onButtonFocus('link7');showName()">test7</a><br>
<a id="link8" href="#" onMouseOver="onButtonFocus('link8');showName()">test8</a><br>
<form id="form1" name="form1" action="#" method="get">
id <input name="show" type="text" size="10"><br>
key <input name="textfield" type="text" size="10"><br>
pc key <input name="pckey" type="text" size="10">
</form>
<script>
var currentButtonIndex = 0;
var currentButtonName = "";
var btnLinks = new Array();
</script>
<script>
function getButton(name)
{
for (var i = 0; i < btnLinks.length; i++ )
{
if(btnLinks[i]==name)
{
return i;
}
}
return 0;
}
function setFocus(name)
{
currentButtonIndex = getButton(name);
currentButtonName = name;
document.links[currentButtonIndex].focus();
}
</script>
<script>
function onButtonFocus(id)
{
currentButtonName = id;
currentButtonIndex = getButton(currentButtonName);
}
</script>
<script>
function showName()
{
document.form1.show.value=currentButtonIndex + " " + currentButtonName;
document.form1.textfield.value = currentButtonName;
}
function showKey(name)
{
document.form1.thekey.value=name;
}
</script>
<script>
btnLinks[0] = "link1";
btnLinks[1] = "link2";
btnLinks[2] = "link3";
btnLinks[3] = "link4";
btnLinks[4] = "link5";
btnLinks[5] = "link6";
btnLinks[6] = "link7";
btnLinks[7] = "link8";
</script>
<script>
function init()
{
setFocus("link8");
showName();
}
</script>
<script>
var key_up = 38;
var key_down = 40;
function doEvent(eventKey, key, srcId, focusId)
{
if(eventKey == key && currentButtonName==srcId)
{
setFocus(focusId);
}
}
function keyPress(keyval)
{
doEvent(keyval, key_up, "link8", "link7");
doEvent(keyval, key_down, "link7", "link8");
}
function keyEvent()
{
var val = event.keyCode.toString();
return keyPress(val);
}
document.onkeydown=keyEvent ;
</script>
</body>