计算中文、英文、数字、空格的字符像素宽度

<html>
<head>
<META http-equiv="content-type" content="text/html; charset=shift_jis">
<title>TEST</title>
<script type="text/javascript">
function SC(){
document.getElementById("p1").innerHTML = document.FMlog.txt1.value;
//alert(document.FMlog.txt1.value);
alert(document.getElementById("p1").offsetWidth);
}
</script>
</head>
<body bgcolor= "#ffffff">
<form method="post" action="" name="FMlog">
<input name="txt1" type="text" />
<input name="btn1" type="button" onclick="SC()" value="click me"/>
<span id="p1" style="visibility:hidden"></span>
</form>
</body>

</html>

你可能感兴趣的:(JavaScript,html)