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

  • Digital Bounds

    Digital Boun

    19 Temmuz 2013
  • Plugable

    Plugable

    19 Mayıs 2010
  • TheRightTire

    TheRightTire

    14 EKİM 2009