input全角输入改为半角输入

代码:

let str = this.name;

let result = "";

for (var i = 0; i < str.length; i++) {

        if (str.charCodeAt(i) == 12288) {

            result += String.fromCharCode(str.charCodeAt(i) - 12256);

            continue;

        }

        if (str.charCodeAt(i) > 65280 && str.charCodeAt(i) < 65375)

            result += String.fromCharCode(str.charCodeAt(i) - 65248);

            else result += String.fromCharCode(str.charCodeAt(i));

}

// obj.value = result;

this.name=result

猜你喜欢

转载自my.oschina.net/u/3705266/blog/1821353