给出以下代码:
[:input {:type "text"
:value (:text @app-state)
:on-change (fn [e]
(if (= 31 (.-keyCode e))
(println "ENTER")
(println "NOT ENTER")))}]
如何更改if
条件,以便输入按键可以区别于普通键? e
中除target
之外的所有属性似乎都是null。
这是如何解决它:
:on-key-press
(而不是:on-change
),因为“enter”不会触发:on-change
事件(它显然不会改变文字)charCode
而不是keyCode
(不是js的专家,但keyCode
在firefox中对我不起作用)
[:input {:type "text"
:value (:text @app-state)
:on-key-press (fn [e]
(println "key press" (.-charCode e))
(if (= 13 (.-charCode e))
(println "ENTER")
(println "NOT ENTER")))}]
随着key
。
[:input
{:on-key-press
(fn [e]
(if (= (.-key e) "Enter")
(.log js/console "Enter")
(.log js/console "Not Enter")))}]
同样感兴趣的是:on-key-up
和:on-key-down
。