2

[GopherJS] Focus and Blur of DOM Element

 2 years ago
source link: http://siongui.github.io/2016/12/19/gopherjs-focus-and-blur-of-dom-element/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[GopherJS] Focus and Blur of DOM Element

December 19, 2016

Focus and Blur of DOM element via GopherJS.

index.html | repository | view raw

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>GopherJS Focus/Blur of DOM Element Demo</title>
</head>
<body>

<input id="i1" type="text" value="" autofocus>
<br>
<input id="i2" type="text" value="">
<br>
<button id="btn" type="button">click me to change focus!</button>

<script src="app.js"></script>
</body>
</html>

app.go | repository | view raw

package main

import (
	"github.com/gopherjs/gopherjs/js"
)

func main() {
	i1 := js.Global.Get("document").Call("getElementById", "i1")
	i2 := js.Global.Get("document").Call("getElementById", "i2")
	btn := js.Global.Get("document").Call("getElementById", "btn")

	btn.Set("onclick", func(e *js.Object) {
		i1.Call("blur")
		i2.Call("focus")
	})
}

Tested on:

  • Ubuntu Linux 16.04
  • Go 1.7.4
  • Chromium Version 53.0.2785.143 Built on Ubuntu , running on Ubuntu 16.04 (64-bit)

References:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK