查找输入元素的值
Find value of input element
我认为这会非常简单,但似乎我忽略了一些东西。
(ns main.core
(:require [dommy.core :refer-macros [sel sel1]]))
(sel1 :#my-input) => #<[object HTMLInputElement]>
(.value (sel1 :#my-input))
=> #<TypeError: document.querySelector(...).value is not a function>
虽然我不是 100% 为什么 .value
不工作,但以下工作非常出色:
(ns main.core
(:require [dommy.core :as dommy :refer-macros [sel sel1]]))
(sel1 :#my-input) => #<[object HTMLInputElement]>
(dommy/value (sel1 :#my-input))
=> "my-input-value"
在 ClojureScript 中,我们有两种与 JavaScript 互操作的特殊形式:.
和 .-
。
.
应该用于调用对象的方法,.-
应该用于访问属性(包括作为值的函数)。如果您查看 Dommy 库中 value
函数的 source code,您会发现它使用了 .-
特殊形式。
看这里:https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#host-interop
这个备忘单也很有用:https://himera.herokuapp.com/index.html
我认为这会非常简单,但似乎我忽略了一些东西。
(ns main.core
(:require [dommy.core :refer-macros [sel sel1]]))
(sel1 :#my-input) => #<[object HTMLInputElement]>
(.value (sel1 :#my-input))
=> #<TypeError: document.querySelector(...).value is not a function>
虽然我不是 100% 为什么 .value
不工作,但以下工作非常出色:
(ns main.core
(:require [dommy.core :as dommy :refer-macros [sel sel1]]))
(sel1 :#my-input) => #<[object HTMLInputElement]>
(dommy/value (sel1 :#my-input))
=> "my-input-value"
在 ClojureScript 中,我们有两种与 JavaScript 互操作的特殊形式:.
和 .-
。
.
应该用于调用对象的方法,.-
应该用于访问属性(包括作为值的函数)。如果您查看 Dommy 库中 value
函数的 source code,您会发现它使用了 .-
特殊形式。
看这里:https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#host-interop
这个备忘单也很有用:https://himera.herokuapp.com/index.html