简体   繁体   English

修剪和WhiteSpaceTrimmer

[英]Trim and WhiteSpaceTrimmer

I face One problem in JavaScript .What it is now I am using dojo componets in jsp page. 我在JavaScript中遇到一个问题。现在我在jsp页面中使用了dojo组件。 So I changed trim function into WhiteSpaceTrimmer function. 因此,我将修整功能更改为WhiteSpaceTrimmer功能。 But it is working in mozilla Firefox not in IE8.in ie shows one error:var ItemLot=(temp2[1].trim()+"*"+temp2[5].trim()); 但是它不能在IE8.in中的mozilla Firefox中运行,即显示一个error:var ItemLot=(temp2[1].trim()+"*"+temp2[5].trim()); not a method. 不是一种方法。

Here if we remove trim function it is working but my final step takes only trim value. 在这里,如果我们删除修剪功能,则它可以正常工作,但是我的最后一步只需要修剪值。

Older versions of IE do not support the String.trim method. 较旧版本的IE不支持String.trim方法。 You can add this code to your startup code for your page to add the trim method to the String object in case it doesn't exist: 您可以将此代码添加到页面的启动代码中,以便在不存在的情况下将trim方法添加到String对象:

if(!String.prototype.trim) {
  String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g,'');
  };
}

Source: MDN . 资料来源: MDN

Dojo provides methods dojo.trim() and dojo.string.trim() which will use the native String.prototype.trim() method if available, and provide an implementation in JS if not, much like what @jfriend00 suggests. Dojo提供了dojo.trim()dojo.string.trim() ,它们将使用本机String.prototype.trim()方法(如果可用),如果不可用则提供JS中的实现,就像@ jfriend00建议的那样。 If you're using Dojo and you need to support older browsers, you might as well use these. 如果您使用的是Dojo,并且需要支持较旧的浏览器,则不妨使用它们。 Pass in the string as the only argument. 传入字符串作为唯一参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM