js 计算输入框的字节数
来源:互联网 发布:清华 王奇 知乎 编辑:程序博客网 时间:2024/06/06 05:03
<html><head><script language="javascript">function alertLength(){var name = document.main.name.value;window.alert("输入文字:【" + name + "】");var length = countLength(name);window.alert("字节数:" + length);}function countLength(str) { var r = 0; for (var i = 0; i < str.length; i++) { var c = str.charCodeAt(i); // Shift_JIS: 0x0 ~ 0x80, 0xa0 , 0xa1 ~ 0xdf , 0xfd ~ 0xff // Unicode : 0x0 ~ 0x80, 0xf8f0, 0xff61 ~ 0xff9f, 0xf8f1 ~ 0xf8f3 if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) { r += 1; } else { r += 2; } } return r; } </script></head><body><form name="main"><input type="text" name="name"><input type="button" onClick="alertLength()"></form></body></html>原文
0 0
- js 计算输入框的字节数
- 计算输入的字符的字节数
- js 限制输入框的字节数,中文两个字节,英文字母一个字节
- js 计算字符串的字节数
- JS计算字符串的字节数
- JS计算字符串的字节数
- js 计算字符串字节数
- js 计算 字符串 字节数
- 得到输入框的字节数
- 计算数组的字节数
- 计算字符串的字节数
- JS计算字符长度、字节数
- JS计算字符串所占字节数
- JS计算字符串所占字节数
- JS计算字符串所占字节数
- input输入框限制输入字节数
- js计算字符串的字节
- 用脚本判断输入框的字节数
- LeetCode 题解(224) : Merge Sorted Array
- LeetCode-Partition List
- Maximal Square
- LeetCode 题解(225) : Remove Duplicates from Sorted List
- LeetCode 题解(226) : Climbing Stairs
- js 计算输入框的字节数
- Solr 5.3安装和使用
- Bit Manipulation
- LeetCode 题解(227) : Add Binary
- *LeetCode-Number of 1 Bits
- js == 和 === 的不同 (两个等号 三个等号)
- 解密一个U盘
- LeetCode 题解(228) : Plus One
- LeetCode 题解(229) : Remove Element