ocaml
This commit is contained in:
23
ocaml/main.ml
Normal file
23
ocaml/main.ml
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
)
|
||||
Reference in New Issue
Block a user