如何检测“输入"按键试剂? [英] How To Detect "Enter" Keypress in Reagent?
本文介绍了如何检测“输入"按键试剂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下代码:
[:input {:type "text"
:value (:text @app-state)
:on-change (fn [e]
(if (= 31 (.-keyCode e))
(println "ENTER")
(println "NOT ENTER")))}]
如何更改if
条件,以便区分输入的按键和普通的按键?除了target
之外,e
中的所有属性似乎都为空.
How to change the if
condition so that enter keypresses can be distinguished from normal keys? All properties in e
except target
seem to be null.
推荐答案
这是解决方法:
- 您应该听
:on-key-press
(而不是:on-change
), 因为输入"不会触发:on-change
事件(显然不会更改文本) - 输入"的键码是 13 ,而不是 31
-
使用
charCode
代替keyCode
(不是js专家,但是keyCode
在firefox中对我不起作用)
- you should listen to
:on-key-press
(rather than:on-change
), because "enter" doesn't trigger:on-change
event (it obviously doesn't change the text) - key code for "enter" is 13, not 31
use
charCode
instead ofkeyCode
(not an expert in js, butkeyCode
doesn't work for me in 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")))}]
这篇关于如何检测“输入"按键试剂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文