- 相關(guān)推薦
有關(guān)javascript在IE下trim函數(shù)無(wú)法使用的解決方法
首先,javascript的trim函數(shù)在firefox下面使用沒有問(wèn)題:
var test1 = " aa "; test1 = test1.toString(); test1 = test1.trim();
在火狐下這樣用沒有問(wèn)題, 但是在IE下就報(bào)錯(cuò)!
對(duì)此,我們可以修改一下:
String.prototype.trim=function(){return this.replace(/(^s*)|(s*$)/g,"");}
在頭上加上這一句,上面的就可以在IE和FF下都可以運(yùn)行了:
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函數(shù)無(wú)法使用的解決方法】相關(guān)文章:
SATA硬盤無(wú)法使用的原因11-21
Excel中if函數(shù)使用的方法06-16
無(wú)法識(shí)別大硬盤問(wèn)題及解決方法07-16
SATA硬盤無(wú)法用Ghost的原因及解決方法07-16
Word文檔無(wú)法正常打開解決方法01-24