input全角輸入改成半角輸入

代碼:this

let str = this.name;co

let result = "";let

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

相關文章
相關標籤/搜索