javascript用正則表達(dá)式過(guò)濾空格的實(shí)現(xiàn)代碼
<html><head><script type="text/javascript"> // 刪除左右兩端的空格 function trim(str){ $a=str.replace(/(^/s*)|(/s*$)/g, ""); alert($a.length); // alert(str.length); } // 刪除左邊的空格 function ltrim(str){ return str.replace(/(^/s*)/g,""); } // 刪除右邊的空格 function rtrim(str){ return str.replace(/(/s*$)/g,""); } </script> </head><body><form> 刪除左右兩端的空格: <input type="text" value="" onblur= "trim(this.value)"><br/> 刪除左邊的空格: <input type="text" value="" onblur= "ltrim(this.value)"><br/> 刪除右邊的空格 <input type="text" value="" onblur= "rtrim(this.value)"></form></body></form>以上這篇javascript用正則表達(dá)式過(guò)濾空格的實(shí)現(xiàn)代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注