24 lines
510 B
OCaml
24 lines
510 B
OCaml
|
|
open Js_of_ocaml
|
||
|
|
(* open Js_of_ocaml.Dom_html *)
|
||
|
|
|
||
|
|
let document = Dom_html.document
|
||
|
|
|
||
|
|
let by_id id =
|
||
|
|
Js.Opt.get
|
||
|
|
(document##getElementById (Js.string id))
|
||
|
|
(fun () -> failwith ("Missing element: " ^ id))
|
||
|
|
|
||
|
|
let () =
|
||
|
|
let button = by_id "btn" in
|
||
|
|
let output = by_id "output" in
|
||
|
|
|
||
|
|
let clicks = ref 0 in
|
||
|
|
|
||
|
|
button##.onclick :=
|
||
|
|
Dom_html.handler (fun _ ->
|
||
|
|
incr clicks;
|
||
|
|
output##.textContent :=
|
||
|
|
Js.some (Js.string ("Clicked " ^ string_of_int !clicks ^ " times"));
|
||
|
|
Js._false
|
||
|
|
)
|