form表单与模板引擎

197 阅读1分钟

一、form表单的基本使用

  1. 表单标签

    (1)action :URL地址

    (2)method :请求方式

    (3)target属性用来规定在何处打开

    ​ 1._blank 新窗户打开

    ​ 2._self 在相同

二、模板引擎

他可以根据程序员指定的模板结构与数据自动生成一个完整的HTML结构

  1. 好处:

    ​ 1,减少字符串的拼接

    ​ 2.使代码更加简洁

    ​ 3.使代码更易于阅读

  2. art-template模板引擎

    ​ 数据

    ​ ======》模板引擎 ======》HTML结构

    模板结构

    模板结构:

    <script type="text/html" id="moban"> </script>
    

    调用引擎方法:template("moban")

  3. 使用步骤:

    1.导入art-template
    2.定义数据
    3.定义模板
    4.调用template函数
    5.渲染HTML结构
    
  4. art-template标准语法

    1.{{}}语法被称为标准语法
    在标准语法中可以传值  三元表达式  短路运算
    2.{{@ title}} 原文输出 保留HTML格式
    3.{{each arr }}
    	<li> {{$index}} </li>     循环输出  可遍历
      {{/each}}
    4.{{if 参数}}  按需要填入内容  {{/if}}
      {{if 参数}}  按需要填入内容  {{else if 参数}}  按需要填入内容  {{/if}}
    
  5. 过滤器:

    ​ 语法:template.defaults.imports.dateFormat=function( ){ }

三、正则与字符串操作

  1. 基本语法:

    ​ exec()

    例如:let str="hello"

    ​ let reg=/h/

    ​ let result=reg.exec(str)

    ​ console.log(result) 返回一个数组

    注意:正则匹配成功返回一个数组 匹配失败返回null

  2. 字符串替换 str=str.replace(result[0],"*");

  3. 搜索编组:const reg=/{{([a-zA-Z])}}/