go - 在 WASM 上添加 addEventListener("click", f)
问题描述
我能够添加一个带有 nonclick
操作的按钮,如下所示:
var f js.Func
f = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
defer f.Release()
Window.Call("alert", "Hello World")
// or
// alert := Window.Get("alert")
// alert.Invoke("Hello World")
return nil
})
// f = function(){ alert("Hello World") };
var Window = js.Global()
// document = window.document
document := Window.Get("document")
// btn = document.createElement("button")
btn := document.Call("createElement", "button")
// btn.innerText = "Click me"
btn.Set("innerText", "Click me")
// btn.style.background='#000000';
btn.Get("style").Call("setProperty", "background-color", "blue")
// btn.onclick = f
btn.Set("onclick", f)
// document.body.appendChild(btn)
document.Get("body").Call("appendChild", btn)
它工作得很好,但我尝试复制 JS 代码:
btn.addEventListener("click",function(event){ f });
作为:
btn.Call("addEventListener", "click", f )
// or
btn.Call("addEventListener").Set("click", f)
但是他们都没有工作,知道为什么吗?
解决方案
推荐阅读
- c++ - 在 GDB 调试器中显示 cv2 Mat
- security - 就 Istio Policy 而言,“peer”和“origin”是什么意思?
- c# - 将数据从 TextBox 分配给变量(C#,WPF)
- python - 将图像从一个文件复制到python文件夹
- hadoop - HDFS:Errno 22 尝试编辑已挂载的 NFS 卷中的现有文件
- javascript - Node Red UI模板如何清除缓存
- c# - 将带有 CefSharp 的用户控件添加到 WinForms 应用程序
- javascript - HightCharts:如何将饼图位置对齐到容器的右角或左角
- java - 如何为 Webapp 创建公共 url
- google-api - 谷歌知识图 API 使用