html dom对象常用事件,HTML Dom Event对象onkeydown事件
語法:
οnkeydοwn="SomeJavaScriptCode"
onkeydown 事件會在用戶按下一個鍵盤按鍵時發生,
ie瀏覽器使用event.keyCode獲取被按下的字符,而 Netscape/Firefox/Opera 使用 event.which。
支持該事件的 HTML 標簽:
, ,
, , , , , , ,, , , , , , , , , ,, , to , , , , , , ,, , , , , , , , , , , , , , , , , ,, , , , , 支持該事件的 JavaScript 對象:document, image, link, textarea例:禁止在輸入框中輸入數字:function caninput(e){var Presskey;var presskeyString;var regstr;if(window.event) // 如果是ie瀏覽器{Presskey = e.keyCode;}else if(e.which) // 如果是Netscape/Firefox/Opera瀏覽器{Presskey = e.which;}presskeyString = String.fromCharCode(Presskey);//將Unicode碼轉換為對應的字符并返回為字符串regstr = /\d/;//數字的正則表達式return !regstr.test(presskeyString);//驗證是否是數字,是就返回false,不是就返回true}
總結
以上是生活随笔為你收集整理的html dom对象常用事件,HTML Dom Event对象onkeydown事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 批量html转换成excel,Excel
- 下一篇: html中flash的使用,[转载]fl