- 相關推薦
有關javascript在IE下trim函數無法使用的解決方法
首先,javascript的trim函數在firefox下面使用沒有問題:
var test1 = " aa "; test1 = test1.toString(); test1 = test1.trim();
在火狐下這樣用沒有問題, 但是在IE下就報錯!
對此,我們可以修改一下:
String.prototype.trim=function(){return this.replace(/(^s*)|(s*$)/g,"");}
在頭上加上這一句,上面的就可以在IE和FF下都可以運行了:
String.prototype.trim=function(){return this.replace(/(^s*)|(s*$)/g,"");} var test1 = " aa "; test1 = test1.toString(); test1 = test1.trim();
JQuery提供的方法:
Show Trim Example
$("button").click(function () { var str = " lots of spaces before and after "; alert(" + str + "); str = jQuery.trim(str); alert(" + str + - no longer"); });
【javascript在IE下trim函數無法使用的解決方法】相關文章:
SATA硬盤無法使用的原因11-21
Excel中if函數使用的方法06-16
移動硬盤無法顯示解決方法12-29
無法識別大硬盤問題及解決方法07-16
Word文檔無法正常打開解決方法01-24
excel中sumif函數使用方法03-23
Excel中COUNTIF函數的使用方法01-23
如何調試javascript腳本呢07-19
javascript跨域訪問的方法07-19