<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <input id="text" type="text"/> <input type="button" value="去除空格" onclick="trimstr()" /> <script type="text/javascript"> function trimstr(str){ return str.replace(/(^\s*)|(\s*$)/g,"") } function trimstr(){ var str=document.getElementById("text").value; console.log(str.length); console.log(trimstr(str).length); } </script> </body></html>
添加回答
举报
0/150
提交
取消