- 怎么知道页面表单是否改动的通用方法
async mounted() {
this.SetInputChange(document.querySelectorAll("input"));//所有input控件注册keydown事件
}
/**
* input输入字符则视为页有变动
* @param iptArr
*/
public SetInputChange(iptArr: any) {
let that = this;
for (let index = 0; index < iptArr.length; index++) {
//添加事件
iptArr[index].addEventListener("keydown", (e) => {
that.FormChage(e.keyCode.toString());
});
}
}
/**
* 是否按下了字符类按键,是则界面内容变动
* @param kyCode
*/
public FormChage(kyCode: string) {
//键盘码(非字符,如ESC、F1等)
let noCharKey = '27,112,113,114,115,116,117,118,119,120,121,123,44,145,19,45,36,33,35,34,9,13,20,16,17,91,18,92,93,38,37,39,40,144'.split(',');
if (!noCharKey.includes(kyCode)) {
sessionStorage.setItem('form_isChange', '是');
}
}
标签:改动,index,kyCode,iptArr,表单,let,input,页面
From: https://www.cnblogs.com/anjun-xy/p/16709809.html