替换最后一个匹配项
使用方法:replace
使用replace匹配的是第一个匹配项,或者使用g进行全局匹配,与需求不符
匹配最后一个匹配项并替换,需要用到一种贪婪模式
var str = 000p111p222p333
str = str.replace(/(.*)p/, '$1div')
console.log(str) //000p111p222div333
history.back(-1)和history.go(-1)的区别
history.back(-1)//直接返回当前页的上一页,数据全部消息,是个新页面
history.go(-1)//也是返回当前页的上一页,不过表单里的数据全部还在
总结:
window.location.reload() //刷新
window.history.go(1) //前进
window.history.go(-1) //后退
window.history.forward() //前进
window.history.back() 后退+刷新
字符与ASCII码互转的方法
大写字母A-Z对应的ASCII码值是65-90
小写字母a-z对应的ASCII码值是97-122
将字母转为ASCII码的方法:
var str = "A";
str.charCodeAt(); // 65
var str1 = 'a';
str1.charCodeAt(); // 97
将ascii码转为对应字母的方法:
var num = 97;
String.fromCharCode(num); // 'a'
var num1 = 100;
String.fromCharCode(num1); // 'd'