Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
做一些文章詳情頁的時候,因為用到了富文本編輯器,因此數(shù)據(jù)庫中存儲的是HTML格式的內(nèi)容,當從數(shù)據(jù)庫中讀取顯示到頁面時需要進行轉換,否則顯示就是實際的字符串內(nèi)容,因此需要進行轉換,轉換的代碼很簡單,就是通過關鍵函數(shù)template.HTML
示例如下:
"content": template.HTML(a.Content),
另外可以自定義模板函數(shù),在模板文件中使用:
package main
import (
"html/template"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.SetFuncMap(template.FuncMap{
"safe": func(str string) template.HTML {
return template.HTML(str)
},
})
router.LoadHTMLFiles("./index.tmpl")
router.GET("/index", func(c *gin.Context) {
c.HTML(200, "index.tmpl", "<a href='lizhouwen.com'>1232</a>")
})
router.Run(":9999")
}
html代碼如下:
兒這個小分享,道哥給大家分享下js中怎么動態(tài)輸出一個表格到頁面上,這里面呢就涉及到兩個大的知識點 一個是document.wiite一個是for循環(huán)。請看下例
<script type="text/javascript"> //打印一個表格 在外層循環(huán)呢先把table標簽打印出來 document.write('<table border="1" style="width:500px;">') //下面用for循環(huán)開始動態(tài)的逐一打印tr和td //第一層for循環(huán)循環(huán)行 tr //打印一個十行十列的表格 //并且根據(jù)奇偶行和列設置不同的背景顏色 for(var j=0;j<10;j++) { if(j%2 ==0) { document.write("<tr>") }else { document.write("<tr style='background:green'>") } //內(nèi)層循環(huán)循環(huán)列 td for(var i=0;i<10;i++) { //判斷列的奇偶性 if(i%2==0) { document.write("<td style='background:gray'>"+i+"</td>") }else { document.write("<td>"+i+"</td>") } } document.write("</tr>") } //表格的結尾 document.write("</table>") </script>
實現(xiàn)結果如下
*請認真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。