SORU
22 ŞUBAT 2010, PAZARTESİ


.YANİ çalışan JavaScript() trim

JavaScript benim programlardan birinde bir dize için .trim() uygulamaya çalıştım. Mozilla altında iyi çalışıyor, ama bir hata IE8 denediğimde görüntüler. Herkes burada neler olduğunu biliyor mu? Bu IE yapabilirim zaten var mı?

kod:

var ID = document.getElementByID('rep_id').value.trim();

görüntü hata:

Message: Object doesn't support this property or method
Line: 604
Char: 2
Code: 0
URI: http://test.localhost/test.js

CEVAP
22 ŞUBAT 2010, PAZARTESİ


Aşağıdaki kod string trim işlevsellik eklemek için.

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

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • bobono1baby

    bobono1baby

    14 AĞUSTOS 2011
  • Flohoo

    Flohoo

    12 EYLÜL 2009
  • SunsetTrance

    SunsetTrance

    20 EYLÜL 2008