日期:2014-05-16  浏览次数:20403 次

js去除两头的空格

<html>
?<head>
<script>
?? function ccc(str){
??????? alert(str.value.length);
??? ??? alert(str.value.replace(/(^\s*)|(\s*$)/g, "").length);
??? ??? return str.value.replace(/(^\s*)|(\s*$)/g, "");
?? }
</script>
?</head>

?<body>
?? <input type="text" value="??? jacklucy?? " onclick="ccc(this);">
?</body>
</html>

?

?

//---------------------------------

?

?

?

function mytrim(str){ //删除左右两端的空格
??? return str.replace(/(^\s*)|(\s*$)/g, "");
}

?

?

?

?

?

?

?