1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 9 <script type="text/javascript"> 10 // var str=' jgo '; 11 function qckg(str){ 12 13 console.log(str) 14 var reg=/(^\s* | \s*$)/g 15 console.log(str.replace(reg, '')) 16 } 17 18 qckg(' ftfg ') 19 20 </script> 21 </body> 22 </html>