[問題] 擷取鍵盤輸入字元

看板Web_Design作者 (Prison Break好看!)時間16年前 (2009/12/22 23:38), 編輯推噓0(007)
留言7則, 4人參與, 最新討論串1/1
你好: 我撰寫以下程式來顯示出使用者在textbox中所按的字元碼 Textbox1.Attributes.Add("onkeypress", "check(event);"); -------------------------------------------------------- <body> <form id="form1" runat="server"> <asp:TextBox ID="TT" runat="server" onkeypress="check(event)"></asp:TextBox> </form> </body> </html> <script type="text/javascript" > function check(e) { var keyCode = (window.event) ? e.which:e.KeyCode; alert(keyCode); } </script> 問題: 如果我在 google chrome執行的話 可以正確顯示出字元碼(十進位) 但如果我在 IE 8 上執行的話 為什麼都跳出 undefined 呢? 是IE 8不支援嗎? 謝謝~ 環境: windows xp , visual studio 2008 sp1 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.195.24.18

12/22 23:52, , 1F
直接 alert(e.KeyCode) 不行嗎?
12/22 23:52, 1F

12/23 00:20, , 2F
剛剛試了 不行耶 一樣是undefined .....不知道問題出在哪說.
12/23 00:20, 2F

12/23 10:16, , 3F
window.event有的話就要拿window.event啊
12/23 10:16, 3F

12/23 10:17, , 4F
ie底下是不會傳 event 的 , 要自己透過系統變數去要.
12/23 10:17, 4F

12/23 10:17, , 5F
反之firefox 就吃 event param
12/23 10:17, 5F

12/23 10:40, , 6F
e = e || window.event; alert(e.keyCode);
12/23 10:40, 6F

12/23 21:11, , 7F
結果是KeyCode出問題 要寫成 keyCode .....感謝指導~
12/23 21:11, 7F
文章代碼(AID): #1BCEVzli (Web_Design)