有關javascript在IE下trim函數無法使用的解決方法
- 網頁設計
- 關注:2.67W次
首先,javascript的'trim函數在firefox下面使用沒有問題:
var test1 = " aa "; test1 = ring(); test1 = ();
在火狐下這樣用沒有問題, 但是在IE下就報錯!
對此,我們可以修改一下:
=function(){return ace(/(^s*)|(s*$)/g,"");}
在頭上加上這一句,上面的就可以在IE和FF下都可以運行了:
=function(){return ace(/(^s*)|(s*$)/g,"");} var test1 = " aa "; test1 = ring(); test1 = ();
JQuery提供的方法:
Show Trim Example
$("button")k(function () { var str = " lots of spaces before and after "; alert(" + str + "); str = (str); alert(" + str + - no longer"); });
- 文章版權屬於文章作者所有,轉載請註明 https://xuezhezhai.com/zh-hk/sjzz/sjzz/z4dlow.html