<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>测试去空格</title>
<script type="text/javascript" src="http://bj.xdf.cn/Portals/24/xdf_common/js/jquery-1.4.2.min.js"></script>
<style type="text/css">
</style>
</head>
<body>
<script>
String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};
$(function(){
var a = ' ',
b = ' b',
c = 'c ',
d = ' d ',
e;
console.log(a);
console.log(b);
console.log(c);
console.log(d);
console.log(e);
console.log(a.trim());
console.log(b.trim());
console.log(c.trim());
console.log(d.trim());
console.log(e ? e.trim() : '');
console.log(a.length);
console.log(b.length);
console.log(c.length);
console.log(d.length);
console.log(a.trim().length);
console.log(b.trim().length);
console.log(c.trim().length);
console.log(d.trim().length);
});
</script>
</body>
</html>
测试去空格
最新推荐文章于 2022-08-12 17:59:59 发布