js 删除字条串首尾空格
<script type="text/javascript" language="javascript">
function caculate()
{
var flag =" 中国 ";
alert(flag+"原长度为:"+flag.length);
alert(flag+"删除首尾空格后,长度为:"+flag.trim().length);
}
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
</script>