我正在尝试用试剂编写可重复使用的标签控件。我需要做的是在用户单击祖先div元素后关注输入字段。为了更清楚,我希望在用户点击div form-element 之后,将重点放在使用类 tag-input 的输入上。如何实现它?
[:div.form-element
[:div.some-other-class
[:ul
[:li "entered-tag"]
]
]
[:input.tag-input {:type "text"}]
]
答案 0 :(得分:1)
你必须实现一些oldschool点击处理我猜:
[:div.form-element
{:on-click #(do (println :click-click)
(.focus (.getElementById js/document "my-input")))}
[:div.some-other-class
[:ul [:li "entered-tag"]]]
[:input.tag-input {:type "text" :id "my-input"}]]
所以你可能应该为这个表单元素创建一些工厂函数:
(defn form-element [id]
[:div.form-element
{:on-click #(.focus (.getElementById js/document id))}
[:div.some-other-class
[:ul [:li "entered-tag"]]]
[:input.tag-input {:type "text" :id id}]])
并像这样使用它:
[:div
(form-element "form-element-1")
(form-element "form-element-2")]
对我来说很好用