當我調用Go模板函數以輸出HTML時,它將顯示ZgotmplZ。樣例代碼:http://play.golang.org/p/tfuJa_pFkmpackage mainimport ( "html/template" "os")func main() { funcMap := template.FuncMap{ "printSelected": func(s string) string { if s == "test" { return `selected="selected"` } return "" }, "safe": func(s string) template.HTML { return template.HTML(s) }, } template.Must(template.New("Template").Funcs(funcMap).Parse(` <option {{ printSelected "test" }} {{ printSelected "test" | safe }} >test</option> `)).Execute(os.Stdout, nil)}輸出:<option ZgotmplZ ZgotmplZ >test</option>
為什么我在Go HTML模板輸出中看到ZgotmplZ?
慕田峪7331174
2021-05-16 09:08:07