試試這個 - 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