2012-12-21 76 views
0
{{if inventory.title.length > 38}} 
      <p class="p1"> 
       {{>(inventory.title.substring(0, 38) + '...').trim()}} 
      </p> 

如何更正此代碼以顯示在IE9之前的IE中。我繼續得到以下字符串修剪不顯示在IE之前9

Error: Object doesn't support property or method 'trim'.

回答

1

修剪是不是字符串的一部分,直到ECMAScript的5 IE9是第一個瀏覽器支持的ECMAScript 5

雖然不建議修改基類的原型,
如果你願意,你可以添加以下幾行代碼來讓String.trim在所有瀏覽器中工作。

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

欲瞭解更多詳情,請參閱[** **這裏(http://stackoverflow.com/a/8522376/1577396) –

+0

哪裏該被添加? – user1920546

+0

@ user1920546使用前的任何地方。最好靠近所有腳本的頂部 – Ian