【www.gdgbn.com--C语言】
jquery.trim( str )
//返回字符串;
//从字符串的头部和尾部移除空格。
//从字符串的头部和尾部移除空格、换行符、制表符。字符串“中部(中间)”的空格、换行符、制表符是不移出的。
//jquery的换行符是 n
// used for trimming whitespace
trimleft = /^s+/,
trimright = /s+$/,// use native string.trim function wherever possible
trim: trim ?
function( text ) {
return text == null ?
"" :
trim.call( text );
} :// otherwise use our own trimming functionality
function( text ) {
return text == null ?
"" :
text.tostring().replace( trimleft, "" ).replace( trimright, "" );
},
看一个实例应用
<script src="http://code.jquery.com/jquery-1.5.js"></script>
<script>$("button").click(function () {
var str = " lots of spaces before and after ";
alert(""" + str + """);str = jquery.trim(str);
alert(""" + str + "" - no longer");
});</script>
从上面实例中可以看出jquery.trim函数其实与js中的trim是很像的,我记得前天我还写过一个php教程 trim函数它们都大同小义了,好了费话就说到这里。