JS trim函数
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script>
function trim(name) {
return name.replace(/^\s+/, '').replace(/\s+$/, '');
}
var msg = ' 我是字符串 ';
//msg = msg.replace(/^\s+/, '').replace(/\s+$/,'');
//alert('========'+msg+'============');
alert('========' + trim(msg) + '========');
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script>
function trim(name) {
return name.replace(/^\s+/, '').replace(/\s+$/, '');
}
var msg = ' 我是字符串 ';
//msg = msg.replace(/^\s+/, '').replace(/\s+$/,'');
//alert('========'+msg+'============');
alert('========' + trim(msg) + '========');
</script>
</head>
<body>
</body>
</html>