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

  • BioHunta

    BioHunta

    28 Mayıs 2006
  • GUN-TIME with Brandon

    GUN-TIME wit

    3 ŞUBAT 2009
  • pjtoohot

    pjtoohot

    15 NİSAN 2008