使用 Closure 库向 Button 添加事件
(ns so-doc.events
(:require
[goog.dom :as dom]
[goog.events :as events]))
(defn handle-click [event] ;an event object is passed to all events
(js/alert "button pressed"))
(events/listen
(dom/getElement "button"); This is the dom element the event comes from
(.-CLICK events/EventType); This is a string or array of strings with the event names.
;;All event names can be found in the EventType enum
handle-click ;function that should handle the event
)
Google Closure 不支持页面加载事件,并认为它们不是惯用的。他们建议在加载访问的内容后立即插入脚本。