php:trim()
js:
- <script>
- <!--
- function trim(s) {
- var count = s.length;
- var st = 0; // start
- var end = count-1; // end
- if (s == "") return s;
- while (st < count) {
- if (s.charAt(st) == " ")
- st ++;
- else
- break;
- }
- while (end > st) {
- if (s.charAt(end) == " ")
- end --;
- else
- break;
- }
- return s.substring(st,end + 1);
- }
- function check(){
- var str=' abc ';
- alert(str.length);
- alert(trim(str).length);
- }
- //-->
- </script>
- <body onload="check()">
- </body>
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/941656,如需转载请自行联系原作者