Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IE8和JQuery';s trim()_Jquery_Internet Explorer_Internet Explorer 8_Trim - Fatal编程技术网

IE8和JQuery';s trim()

IE8和JQuery';s trim(),jquery,internet-explorer,internet-explorer-8,trim,Jquery,Internet Explorer,Internet Explorer 8,Trim,我正在使用trim()如下所示: 其中,group\u字段是文本类型的输入元素。这在Firefox中有效,但当我在IE8上尝试时,会出现以下错误: Message: Object doesn't support this property or method 当我拆下饰件()时,它在IE8上工作正常。我认为我使用trim()的方式是正确的 感谢所有人的帮助请尝试以下方法: if($.trim($('#group_field').val()) != ''){ 更多信息: 您应该这样使用:

我正在使用trim()如下所示:

其中,
group\u字段
是文本类型的输入元素。这在Firefox中有效,但当我在IE8上尝试时,会出现以下错误:

Message: Object doesn't support this property or method
当我拆下饰件()时,它在IE8上工作正常。我认为我使用trim()的方式是正确的

感谢所有人的帮助

请尝试以下方法:

if($.trim($('#group_field').val()) != ''){
更多信息:

您应该这样使用:

if($.trim($('#group_field').val()) !='') {
    // ...
}

据我所知,Javascript字符串没有方法trim。 如果要使用功能修剪,请使用

<script>
    $.trim(string);
</script>

$.trim(字符串);

要使用jQuery全局修剪输入,请键入文本:

/**
 * Trim the site input[type=text] fields globally by removing any whitespace from the
 * beginning and end of a string on input .blur()
 */
$('input[type=text]').blur(function(){
    $(this).val($.trim($(this).val()));
});

另一个选项是直接在
String
上定义方法,以防丢失:

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    //Your implementation here. Might be worth looking at perf comparison at
    //http://blog.stevenlevithan.com/archives/faster-trim-javascript
    //
    //The most common one is perhaps this:
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}
无论使用何种浏览器,
trim
都会起作用:

var result = "   trim me  ".trim();

谢谢,我认为JQuery的函数是可链接的,它们就是这样工作的@Abs:
val()
不返回jQuery对象,因此不能使用链接。您对字符串调用了
trim()
方法,但IE不知道
string.trim
.FWIW,我只是因为某人使用了OP的语法而未能通过代码审阅。很明显,他们没有在任何版本的MSIE中进行测试。改为使用jQuery.inArray()。
var result = "   trim me  ".trim();