---
title: "javascript at IE of trim problem"
author: "夜鸣猪"
date: "2013-03-06T04:02:27Z"
tags: []
categories: ["编程语言"]
slug: "javascript-at-ie-of-trim-problem"
draft: false
lastmod: "2013-03-06T04:02:27Z"
id: 1823015
url: "https://hlee.iteye.com/blog/1823015"
---

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

```



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

```js

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}

//Use Jquery
$.trim( $("#mycomment").val() );
if ($(this).val().trim() == "")
var originalValueTrimmed = $.trim($(this).val());              
            if (originalValueTrimmed  == "") { ... }



```




```js

if($('#group_field').val().trim()!='')
//should be
if($.trim($('#group_field').val()) != ''){


```