JavaScript拆分功能在IE中不起作用 [英] JavaScript split function not working in IE

查看:81
本文介绍了JavaScript拆分功能在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中使用split函数。它在Firefox和Chrome中运行良好,但是当我调用split函数时,IE显示错误。有没有办法使用其他功能,如分裂?

I am using the split function in JavaScript. It works fine in Firefox and Chrome, but IE displays an error when I call the split function. Is there a way to use other function like split?

推荐答案

拆分方法

IE8完全支持它

JScript 5.6的拆分方法

IE6也完全支持它

< a href =http://jsfiddle.net/UqAET/3/ =noreferrer>实例使用 .split(/ \ s + /)

在IE9标准,IE9 IE8模式,IE9 IE7模式和IE9怪癖模式下测试。所有工作。

Tested in IE9 standards, IE9 IE8 mode, IE9 IE7 mode and IE9 quirks mode. All work.

修改:

原来你的实际问题是使用 .textContent 。这在IE中不起作用。有两种选择。

Turns out your actual problem is using .textContent. This does not work in IE. There are two alternatives.

功能检测:

var str;
if (el.textContent) {
  str = el.textContent;
} else {
  str = el.innerText;
}

.nodeValue:

var str = el.nodeValue;

这篇关于JavaScript拆分功能在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆