在 golang 上使用 HTML 模板

对不起,我是初学者,我阅读了 golang.docs,但不太了解。我已经:index.html:


<html>

<head>

</head>

<body>

<form action type="checkbox" name="test" value="A" {{.checked}}>

<input type="submit" value="save">

</body>

</html>

在 main.go 中,如果用户单击保存按钮然后选中复选框重定向该页面并显示复选框已选中


长风秋雁
浏览 188回答 2
2回答

慕盖茨4494581

将.在Go代码中定义。请提供执行模板的 go 代码片段,类似于以下代码:&nbsp;&nbsp;&nbsp;&nbsp;t,&nbsp;_&nbsp;:=&nbsp;template.ParseFiles(tmpl&nbsp;+&nbsp;".html") &nbsp;&nbsp;&nbsp;&nbsp;t.Execute(w,&nbsp;data)&nbsp;//&nbsp;the&nbsp;data&nbsp;must&nbsp;feature&nbsp;the&nbsp;field&nbsp;"checked"或者&nbsp;&nbsp;&nbsp;&nbsp;templates.ExecuteTemplate(w,&nbsp;tmpl+".html",&nbsp;data)&nbsp;//&nbsp;the&nbsp;data&nbsp;must&nbsp;feature&nbsp;the&nbsp;field&nbsp;"checked"您可以将任何类型(接口{})传递给将模板作为“数据”执行的函数。通常它是一个 Struct 或一个 Map[string]string。如何设置checked&nbsp;可能“checked”是在main.go at handler 中根据posted form 设置的。阅读文档并更好地解释它。请
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go