且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在普通的Javascript文件中使用JQuery trim()函数?

更新时间:2023-12-03 19:47:22

 <   html  > 
<  头部 > 
  <  脚本    ="   http://code.jquery.com/jquery-1.5. js" <  > 
<  /head  > 
<  正文 > 
  <  按钮 > 显示修剪示例<  /button  > 
<  脚本 >  

("button").click(function(){ var str =前后有很多空格"; alert('" + str +'"); str = jQuery.trim(str); alert('" + str +'-不再"); }); < /script > < /body > < /html >


有几种方法可以使用字符串对象 [ ^ ].

声明一个字符串,为其分配文本框值,然后使用字符串方法来实现修整功能.如果需要,将字符串值分配回文本框.

下面是一个示例: JavaScript字符串修剪 [.trim() == ""){ .......... .......... }



when this line execute by the browser on clinet side

it shows the error "Object doesn''t support this property or method Error"

How to use the trim() function in javascript

Please Help me

Thanks in Advance...

<html>
<head>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
  <button>Show Trim Example</button>
<script>


("button").click(function () { var str = " lots of spaces before and after "; alert("'" + str + "'"); str = jQuery.trim(str); alert("'" + str + "' - no longer"); }); </script> </body> </html>


There are few methods to achieve trim using string object[^].

Declare a string, assign the textbox value to it and then use string methods to achieve trim feature. If needed, assign back the string value to textbox.

Here an example: Javascript string Trim[^]