Web
window 事件
onbeforeunload
- 页面关闭或重载前会执行
- console.log 不会输出
1 | window.onbeforeunload = function(e) { |
localStorage
- localStorage只能存储字符串数据
- 存储 json 对象时:先把json对象转换成字符串
JSON.stringify(jsonObj)
,然后用 localStorage 存储起来 - 获取时:先读取出来,再转换成json对象
JSON.parse(cacheData)
1 | // 存储 |
data 扩展属性
1 | data-cur="hello" |
上传文件限制类型为图片
其它类型限制参考《Web-input-file》
1 | <input type="file" name="myImage" accept="image/*" /> |
Chrome 中打开 IE 浏览器,跳转到指定页面并传递参数
为方便使用,使用winrar
将指定目录打包为exe
,参考文档《Windows-winrar打包exe.md》
示例
1
2
3
4
5
6
7
8
9
10
<html lang="en">
<head>
<meta charset="UTF-8">
<title>调用本地 IE 浏览器打开百度首页</title>
</head>
<body>
<a href="openIE://www.baidu.com?a=1&b=2" />百度一下
</body>
</html>runreg.bat
1
REGEDIT /S openIE.reg
openIE.reg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\openIE]
@="URL:openIE Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\openIE\DefaultIcon]
@="iexplore.exe,1"
[HKEY_CLASSES_ROOT\openIE\shell]
[HKEY_CLASSES_ROOT\openIE\shell\open]
[HKEY_CLASSES_ROOT\openIE\shell\open\command]
@="\"C:\\Program Files\\openIE\\openIE.bat\" \"%1\""openIE.bat
1
2
3
4
5
6
7
8
9
10
11
12
13@echo off
set m=%1%
set m=%m:openIE:=%
IF "%PROCESSOR_ARCHITECTURE%" == "x86" (
start "" "C:\\Program Files\\Internet Explorer\\iexplore.exe" %m%
) ELSE (
IF "%PROCESSOR_ARCHITECTURE%" == "X86" (
start "" "C:\\Program Files\\Internet Explorer\\iexplore.exe" %m%
) ELSE (
start "" "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe" %m%
)
)
exit
IE 浏览器打开其他浏览器
1 | function start(){ |
关闭表单自动填充
- 浏览器设置-自动填充-关闭
chrome://settings/autofill
- 表单 form 设置
autocomplete="off"
不让浏览器缓存 js
在 html 头部增加如下代码
1
2
3<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">在引用 js 文件的时候,添加随机数
1
document.write("<script type='text/javascript' src='update.js?"+Math.random();+"'></script>");
点击 button 按钮后页面引起刷新
1 | //button 缺少 type=button 属性 |
表单重复提交
鼠标连点,可能导致表单提交多次,请求重复多次。前端应该控制:例如变量控制
readonly & disabled 区别
readonly 和 disabled 是用在表单中的两个属性,它们都能够做到使用户不能够更改表单域中的内容。
disabled:对于所有的表单元素都有效,包括 select, radio, checkbox, button 等。如果一个输入项的 disabled 设为 true,则该表单输入项不能获取焦点,用户的所有操作(鼠标点击和键盘输入等)对该输入项都无效,最重要的一点是当提交表单时,这个表单输入项将不会被提交。
readonly:只针对 input (text /password) 和 textarea 有效;如果设为 true,用户只是不能编辑对应的文本,但是仍然可以聚焦焦点,并且在提交表单的时候,该输入项会作为 form 的一项提交。
相对协议 http/https
可以使用相对协议引入资源,会自动根据站点协议类型添加协议,示例。前提是:资源本身支持两种协议
1 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 王文哲的博客!