javascript问题,帮忙

发布网友

我来回答

4个回答

热心网友

浏览器不通用万恶的IE。。。

this[start] 改成 this.charAt(start)

就可以咯。。

热心网友

弄错了,在Firefox上好用,IE上不行!
<script type="text/javascript">
function trim1() {
var str = this,
whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
for (var i = 0,len = str.length; i < len; i++) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(i);
break;
}
}
for (i = str.length - 1; i >= 0; i--) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(0, i + 1);
break;
}
}
return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
var arr = " abc ";
String.prototype.trim1 = trim1;
var s=arr.trim1();

alert("----"+s+"----");

</script>
两个都成1

热心网友

String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}

IE使用这个吧 去掉空格(正则表达试)

热心网友

----abc----
ie9上也正常啊.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com