mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
28 lines
545 B
Go
28 lines
545 B
Go
package main
|
|
|
|
import (
|
|
"strconv"
|
|
"syscall/js"
|
|
)
|
|
|
|
var a, b int
|
|
|
|
func main() {
|
|
document := js.Global().Get("document")
|
|
document.Call("getElementById", "a").Set("oninput", updater(&a))
|
|
document.Call("getElementById", "b").Set("oninput", updater(&b))
|
|
update()
|
|
}
|
|
|
|
func updater(n *int) js.Func {
|
|
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
|
*n, _ = strconv.Atoi(this.Get("value").String())
|
|
update()
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func update() {
|
|
js.Global().Get("document").Call("getElementById", "result").Set("value", a+b)
|
|
}
|