跳转至

JavaScript笔记

JavaScripts:

  • location.replace(location.href) 只刷新页面,不刷新静态文件,相当于F5.

  • loaction.reload(true) 刷新页面及静态文件,相当于ctrl+F5.

  • 在ajax的success中history.back()\history.go(-1)不生效,需要使用hostory.go(-2)

Html:

  • <input type="file" name="excel" accept=".xls" required> 代表输入类型为file 格式为.xls 在POST中参数名为excel 必填

  • <input type="number" step="any">设置输入数字小数点不限

  • colgroup col标签可以控制表格显示的比例,col为空时表示该行占据剩下的所有宽度,但必须配合 tbody 标签使用使用。eg:

<table class="layui-table" style="margin-top: 10px">
    <colgroup>
        <col width="50">
        <col width="100">
        <col>
        <col width="200">
        <col width="200">
    </colgroup>
    <thead>
    <tr>
        <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" id="allChoose"></th>
        <th style="text-align: center">ID</th>
        <th>标题</th>
        <th style="text-align: center">语言</th>
        <th style="text-align: center">操作</th>
    </tr>
    </thead>

    <tbody>
    <tr></tr>
    </tbody>
</table>
</div>
  • 循环渲染列表时,可以将数据的id绑定给tr的id,这样就可以直接使用dom节点活动tr后,使用 .attr 方法获取到数据id。

  • 循环渲染列表时,需要将循环生成的js代码放置到tr区块中,不然去取index的时候回出现返回0 2 4 6 8 的情况。

  • Django的模板语言运行在后端,js运行在前端,所以django模板语言中的变量不可以出现在js中,只可以使用url反向检索或者将js中的对象转换成str,不可以在js中将django模板变量作为一个变量来使用,只可以作为常量来使用,因为一经过后台渲染后,django的模板变量就变成了常量存在js中了。

  • 在js中使用Django 模板变量时,需要在两端加上“”,将变量转化为当前状态对应的str,如 news_list(Queryset[1,2]),引用格式为“{{news_list}}”,js中得到的结果为“Queryset[1,2]”,其类型str而非Queryset。

  • jquery.js要在bootstrap.js之前引用,因为bootstarp.js需要jquery.js的支持。

  • form中添加novalidate可以禁用本地的预检测程序

  • {% if field.field.required %} # 字段是否必填