整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

肖sir_html之基本使用(1)

、新建项目

1、新建===web项目===输入项目名称====完成


二、新建html文件

在新建项目中新建html模板


输入文件名称:


三、认识基本格式


联想出基本格式:



四、编辑html文件


运行html,选择浏览器



五、html常用的快捷键

(1)ctrl+n+w web项目创建



(2)ctrl+n+h html文档创建


(3)ctrl+s 保存html页面(页面上如果未保存会显示*号)



(4)ctrl+r html运行
(5)ctrl+z 撤回
(6)!+tab键 联想基本格式
(7)ctrl+/ 注释和取消注释



(8)ctrl+鼠标滚轮, 字体方大和缩小


六、认识标签

(1)H标签(标题标签)



(2)p标签 (段落标签)



(3)img 标签(图片标签)
两种:第一种widows上传图片,第二种:网上图片链接

第一种


img中显示图片

img中引入图片




第二种:网上图片的链接:




(4) 标签(空格)



(5)em 标签表示斜体



(6)i 标签表示斜体



(7)br 表示换行



(8)b 标签表示加粗



(9) strong 标签表示加粗



(10)s 标签(删除线)




(11)u 标签 (下划线)



(12)font 颜色



(13)sub下标
(14)sup上标

们可以使用以下的方式去渲染html

func main() {
	router := gin.Default()
	router.LoadHTMLGlob("templates/*")
	//router.LoadHTMLFiles("templates/template1.html", "templates/template2.html")
	router.GET("/index", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.tmpl", gin.H{
			"title": "Main website",
		})
	})
	router.Run(":8080")
}

在html中我们可以使用特殊的双花括号来渲染title这个值

<html>
	<h1>
		{{ .title }}
	</h1>
</html>

值得注意的是这种方式并不是gin特有的,而是golang特有的,它还有其他的模板语法。


模板语法:

定义变量:

{{$article := "hello"}}

也可以给变量赋值

{{$article := .ArticleContent}}

函数的调用:

{{funcname .arg1 .arg2}}

判断语法:

{{if .condition}}
{{end}}
{{if .condition1}}
{{else if .contition2}}
{{end}}
  • not 非
{{if not .condition}}
{{end}}
  • and 与
{{if and .condition1 .condition2}}
{{end}}
  • or 或
{{if or .condition1 .condition2}}
{{end}}
  • eq 等于
{{if eq .var1 .var2}}
{{end}}
  • ne 不等于
{{if ne .var1 .var2}}
{{end}}
  • lt 小于
(less than){{if lt .var1 .var2}}
{{end}}
  • le 小于等于
{{if le .var1 .var2}}
{{end}}
  • gt 大于
{{if gt .var1 .var2}}
{{end}}
  • ge 大于等于
{{if ge .var1 .var2}}
{{end}}

循环:

{{range $i, $v := .slice}}
{{end}}

引入一个模板:

{{template "navbar"}}