js如何获取页面数据的自己数
一个form表单,里面好多要填写的东西,填好了之后,提交时用js验证一下提交数据的字节数总和,怎么做呢
[解决办法]
如果都是输入框的话可以这样计算:
<input type="text" id="t1" />
<input type="text" id="t2" />
<input type="button" onclick="testBt()" />
<script type="text/javascript">
function testBt()
{
var allstr = '',count=0;
allstr+=document.getElementById('t1').value;
allstr+=document.getElementById('t2').value;
count = allstr.replace(/[^\x00-\xFF]/g,'**').length;
alert('表单中输入的文字一共占了'+count+'个字节');
return count;
}
</script>
[解决办法]
关键是这句正则,算出字符串所占字节数
[字符串].replace(/[^\x00-\xFF]/g,'**').length
[解决办法]