用Jquery去左右的空格
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="js/jquery-2.1.4.js"></script> <script type="text/javascript"> ;(function($){ $.extend({ deleteL :function(V){ return( V || "").replace(/^s+/,"");//防止传经来的为未定义 }, deleteR :function(V){ return( V || "").replace(/s+$/,""); } }); })(jQuery); $(function(){ $("#myDiv").val($.trim(" test ") + " " +$.deleteL(" test ") + "test" + " " +$.deleteR(" test ") ); }); </script> </head> <body> <textarea id="myDiv" rows="20" cols="20"></textarea> </body> </html>