使用github.com/zserge/lorca包编写Golang应用程序。这会将golang函数绑定到Javascript。我有带有文本输入和提交按钮的HTML,该按钮应将文本输入作为arg传递到Javascript绑定中。它看起来如下:<input type="text" name="MACADD" style="height:20px; width:210px"><input type="submit" value="submit" onclick="JSBINDFUNC(MACADD)">的JSBINDFUNC需要golang类型string输入。当我点击Submit时,它应该将输入的文本MACADD作为arg传递到JSBINDFUNCfunc中。但是,我会回来的错误exception":{"type":"string","value":"json: cannot unmarshal object into Go value of type string"}需要这个object成为golang string。更完整的截图:package mainimport ( "fmt" "log" "net/url" "github.com/zserge/lorca")func main() { ui, err := lorca.New("data:text/html,"+url.PathEscape(` <html> <form action="/action_page.php"> MAC Address:<br> <input type="text" name="MACADD" style="height:20px; width:210px"> <input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD)"> </form> </body> </html> `), "", 480, 320) if err != nil { log.Fatal(err) } //ui.Bind implemented @ https://github.com/zserge/lorca/blob/master/ui.go#L110 ui.Bind("JSBINDFUNC", func(MAC string) { fmt.Println(MAC) return }) defer ui.Close() <-ui.Done()}
1 回答

HUWWW
TA贡献1874条经验 获得超12个赞
问题出在您的JavaScript。像这样更新您的onclick属性:
<input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD.value)">
添加回答
举报
0/150
提交
取消