1、创建4个aspx页面page1.aspx,page2.aspx,page3.aspx, page4.aspx
2、打开page1.aspx,添加3个LinkButton,分别指向其余3个页面
<
div
style
="width: 100%; height: 154px;"
>
< asp:LinkButton ID ="lbPage1" runat ="server" PostBackUrl ="Page1.aspx" > 按下数字键“1”跳转到Page 1 </ asp:LinkButton >< br />
< br />
< asp:LinkButton ID ="lbPage2" runat ="server" PostBackUrl ="Page2.aspx" > 按下数字键“2”跳转到Page 2 </ asp:LinkButton >< br />
< br />
< asp:LinkButton ID ="lbPage3" runat ="server" PostBackUrl ="Page3.aspx" > 按下数字键“3”跳转到Page 3 </ asp:LinkButton >< br />
< br />
</ div >
< asp:LinkButton ID ="lbPage1" runat ="server" PostBackUrl ="Page1.aspx" > 按下数字键“1”跳转到Page 1 </ asp:LinkButton >< br />
< br />
< asp:LinkButton ID ="lbPage2" runat ="server" PostBackUrl ="Page2.aspx" > 按下数字键“2”跳转到Page 2 </ asp:LinkButton >< br />
< br />
< asp:LinkButton ID ="lbPage3" runat ="server" PostBackUrl ="Page3.aspx" > 按下数字键“3”跳转到Page 3 </ asp:LinkButton >< br />
< br />
</ div >
3、在page1的PageLoad中注册脚本
protected
void
Page_Load(
object
sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "Shortcut", "document.attachEvent ('onkeyup',ShortcutKeys);", true);
}
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "Shortcut", "document.attachEvent ('onkeyup',ShortcutKeys);", true);
}
4、完成javascript函数ShortcutKeys
在Header中添加下列代码
<
script type
=
"
text/jscript
"
>
function ShortcutKeys()
{
//alert(event.keyCode);
// 1 Pressed For Page1
if (event.keyCode == 49)
{
document.getElementById('lbPage1').click();
}
// 2 Pressed For Page2
if (event.keyCode == 50)
{
document.getElementById('lbPage2').click();
}
// 3 Pressed For Page3
if (event.keyCode == 51)
{
document.getElementById('lbPage3').click();
}
}
< / script>
function ShortcutKeys()
{
//alert(event.keyCode);
// 1 Pressed For Page1
if (event.keyCode == 49)
{
document.getElementById('lbPage1').click();
}
// 2 Pressed For Page2
if (event.keyCode == 50)
{
document.getElementById('lbPage2').click();
}
// 3 Pressed For Page3
if (event.keyCode == 51)
{
document.getElementById('lbPage3').click();
}
}
< / script>