我正在尝试渲染一个html模板
context.HTML(http.StatusOK,
"my_html_template.html",
information)
其中my_html_template.html
有内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My HTML page</title>
</head>
<body>
Please wait. Do not push back or refresh
</body>
<script>
{{if eq .Action "form"}}
var form = "{{.PgData}}";
var elem=document.createElement("div");
elem.innerHTML=form;
document.body.appendChild(elem);
elem.firstChild.submit();
{{end}}
</script>
</html>
我无法理解如何使用内联JS渲染此页面。
渲染页面有<script>
,所有js都是html。最终的html页面看起来像这样。请注意:这是最终用户(而不是终端)的样子。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Page</title>
</head>
<body>
Please wait. Do not push back or refresh
</body>
<script>
var form = "<form>....</form>";
var elem=document.createElement("div");
elem.innerHTML=form;
document.body.appendChild(elem);
elem.firstChild.submit();
</script>
</html>