在打开一个页面时,用键盘输入几个字符后,页面就会自动导航

- 中国WEB开发者网络 (http://www.webasp.net)
-- 网页特效 (http://www.webasp.net/javascript/)
--- 在打开一个页面时,用键盘输入几个字符后,页面就会自动导航 (http://www.webasp.net/javascript/1/777.htm)
-- 发布日期: 2005-07-06
<!-- 网页特效代码由[中国WEB开发者网络:http://www.ChinaWebDev.com]提供! -->
<!-- 要实现此效果需要 1 个步骤: -->

<!-- 第 1 步: -->
<!-- 把下面的代码加到<BODY></BODY>区域中: -->

<script language="JavaScript" src="../news2.js"></script></CENTER>
<center><font color=red face="隶书" size=6>用键盘来导航</font></center>
<br>
<center>
<table border=5 bordercolor=blue borderlight=green>
<tr><td align=center><font size=4 color=red face="Arial, Helvetica, sans-serif"><strong>你用键盘敲条"java"就会看到效果!</strong></font></td></tr>
<tr><td align=left>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var SpecialWord = "java",
SpecialUrl = "http://www.1stscript.com/",
SpecialLetter = 0;
function getKey(keyStroke) {
var isNetscape=(document.layers);
// Cross-browser key capture routine couresty
// of Randy Bennett (rbennett@thezone.net)
var eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
var which = String.fromCharCode(eventChooser).toLowerCase();
if (which == SpecialWord.charAt(SpecialLetter)) {
SpecialLetter++;
if (SpecialLetter == SpecialWord.length) window.location = SpecialUrl;
}
else SpecialLetter = 0;
}
document.onkeypress = getKey;
// End -->
</script>
</td></tr>
</table></center>
<br>
<br><br>
<br><br>
<br>
<center>
<textarea name=source rows=12 cols=45 class=yk9></textarea>

webasp.net