<script>
function trim(str) {
if (str == null) {
return "";
}
return str.replace(/^\s*(.*?)[\s\n]*$/g,'$1');
}
var s=" hello ";
document.writeln("1"+trim(s)+"1");
document.write("1"+s+"1");
</script>
/***********************/
i n Javascript:
去掉leading/trailing 空格: str = str.replace(/^\s+|\s+$/g,"");
去掉all空格: str = str.replace(/\s+/g,"");
posted on 2007-11-19 15:34
Crying 阅读(5973)
评论(0) 编辑 收藏 所属分类:
JavaScript和CSS