版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/86562303
1.效果图
2.HTML代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>78 jQuery-使用trim()函数去除字符串两边的空格</title>
<style type="text/css">
body{font-size: 13px;}
ul{
padding: 0px;
margin: 20px;
list-style-type: none;
width: 260px;
border-top: dashed 1px #ccc;
border-left: dashed 1px #ccc;
border-right: dashed 1px #ccc;
}
ul li{
border-bottom: dashed 1px #ccc;
padding: 8px;
}
.title{
background-color: #eee;
font-weight: bold;
}
div{
margin: 20px;
padding: 10px;
border: solid 1px #666;
background-color: #eee;
width: 300px;
}
</style>
</head>
<body>
<div id="divTip">
</div>
<script src="../jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var strTmp = "内容:";
//前面是中文空格,后面是英文空格
var strOld = " 我是大都督 ";
strTmp += strOld+"<br><br>";
strTmp += "除掉空格符前的长度:"+strOld.length+"<br><br>";
//去除空格
var strNew = $.trim(strOld);
strTmp += "除掉空格符后的长度:"+strNew.length;
$("#divTip").append(strTmp);
})
</script>
</body>
</html>