[html] view plaincopy
<html>
<body>
<script type="text/javascript">
var before="abcdefgh"
var after=before.length
alert(after)//显示结果长度为8
</script>
</body>
</html>
2、截取变量:
[html] view plaincopy
<html>
<body>
<script type="text/javascript">
var before="abcdefgh"
var after=before.substr(0,3)
alert(after)//显示结果abc
</script>
</body>
</html>
3、获取某字符的位置 :
[html] view plaincopy
<html>
<body>
<script type="text/javascript">
var before="abcdefgh"
alert("d的位置为:"+before.indexOf("d"))//结果为3 从0开始的
</script>
</body>
</html>