试试这个 - JS代码this thread
<asp:Button OnClientClick="pressDown();" />
<script>
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
function pressDown() {
keyboardEvent[initMethod](
"keydown", // event type : keydown, keyup, keypress
true, // bubbles
true, // cancelable
window, // viewArg: should be window
false, // ctrlKeyArg
false, // altKeyArg
false, // shiftKeyArg
false, // metaKeyArg
40, // keyCodeArg : unsigned long the virtual key code, else 0
0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0
);
document.dispatchEvent(keyboardEvent);
}
</script>
借你想去哪里被按下键盘按键?用户点击客户端机器上的按钮,而您的代码隐藏在服务器上运行... –
@PaoloTedesco我希望它在用户端被按下。 – SimplyZ