PC端各浏览器JavaScript问题【Chrome、Firefox、IE】——长期更新

版权声明:虽然我很善良,但是原创文章还是问问我再转载哦<( ̄︶ ̄)> https://blog.csdn.net/Vivian_jay/article/details/68060790

一、touchmove事件只能触发一次

解决:touchstart时阻止默认事件

二、HTML5画布清除两种方法

1、使用clearRect:

ctx.clearRect(0, 0, w, w)

2、使用重置画布宽/高:

$canvas.attr("width", 0)
$canvas.attr("width", w)

三、localStorage本地存储

//1. 获取本地存储对象
var storage = window.storage
//2. 添加键值对到本地存储
storage.setItem("password", password)
//3. 从本地存储获取指定值
storage.getItem("password")
storage["password"]
//4. 存储数组:由于localstorage只能存储字符串格式,存数组前将其转化为JSON格式,取出时在解析为数组
storage.setItem( "password", JSON.stringify(password) )
var localPw = storage.getItem("password") || []
localPw = JSON.parse( localPw )

猜你喜欢

转载自blog.csdn.net/Vivian_jay/article/details/68060790