跳到主要內容

發表文章

目前顯示的是 十一月, 2015的文章

讀取鍵盤輸入問題(keyup, keydown, keypress)

若要讀取使用者的鍵盤輸入通常會聽 Keydown 事件,如:
String.fromCharCode(keydownEvent.keycode)
但這方法會將數字鍵盤的 1 的 keycode 轉成字母 a其實同一個按鍵的 keydown.keycode 在各瀏覽器的的值極不一致,這篇專文 JavaScript Madness: Keyboard Events 有深入討論。The keypress events are generally the easiest to work with.結論就是聽 kepress event,並使用 keypress.which原因:
On keydown and keyup events, the keycodes are not character codes, and this conversion will give wild results for many keys. There is no general portable way to convert keycodes to characters. 這篇提到 keydown 跟 keypress 當初設計的用意不同。
http://stackoverflow.com/questions/11030532/keypress-and-keyup-why-is-the-keycode-different
The events are for completely different purposes. Use keyup and keydown for identifying physical keys and keypress for identifying typed characters. The two are fundamentally different tasks with different events; don’t try to mix the two. In particular, keyCode on keypress events is usually redundant and shouldn’t be used (except in older IE, but see the linked document below for more …

ZK 教學 - 在 ZK 元件上設定 HTML attribute - 文法檢查

有些 HTML attribute, ZK 元件並不支援,像 HTML5 spellcheck,這時用 Client Attribute 就可以輕易加上去。<textboxxmlns:ca="client/attribute"ca:spellcheck="true"/>這樣 textbox 就擁有 browser 提供的文法檢查能力了。Client Attribute 是很不錯的設計。雖然 ZK 元件是一個 UI 抽象層,但像這麼簡單的功能就不用做在元件層,這個功能可以直接操作底層 DOM element,彌補抽象層的不足,或可直接得益於底層,不用耗費人力去做一個對應元件 attribute。

iframe DOM 被移動造成重新載入

如果用 javascript 去搬動 iframe DOM 的位置, 瀏覽器會將其內容重新載入,這是現有 HTML 規格
> When an iframe element is inserted into a document that has a browsing context, the user agent must create a nested browsing context, and then process the iframe attributes for the "first time". 範例:
http://jsfiddle.net/pZ23B/
測試結果:
* Safari 3.1 / Win: reload
* Opera 9.5 / Win: reload
* IE10: reload
* IE7 / IE8: not reload
(部份摘自 https://bugzilla.mozilla.org/show_bug.cgi?id=254144)
參考:
* https://bugzilla.mozilla.org/show_bug.cgi?id=254144