我正在使用JavaScript中的拆分函数。它在Firefox和Chrome中运行良好,但当我调用split函数时,IE显示一个错误。有没有办法使用像split这样的其他函数?
发布于 2011-06-21 17:08:12
split Method
它完全由IE8支持
split method for JScript 5.6
IE6也完全支持它
使用.split(/\s+/)的Live example
已在IE9标准、IE9 IE8模式、IE9 IE7模式和IE9 quirks模式下测试。一切正常。
编辑:
事实证明,您的实际问题是使用.textContent。这在IE中不起作用。有两种选择。
功能检测:
var str;
if (el.textContent) {
str = el.textContent;
} else {
str = el.innerText;
}.nodeValue:
var str = el.nodeValue;
发布于 2013-07-11 01:55:38
当您拆分数字而不是字符串时,Javascript抛出的对象不支持此属性。
确保在var中有一个字符串值。
发布于 2011-06-21 20:45:24
在处理字符串拆分时,#9以下的IE与大多数其他浏览器至少有一个区别-
var s=‘在某些浏览器中,您可以在带括号的分隔符上“拆分”字符串,并返回数组中的“拆分”位。’;
s.split(/( ?['"] ?)/).join('\n')
/***************************************************/
Firefox 4.0.1>>
In some browsers, you can
"
split
"
a string on a parenthized delimeter and return the
"
split-off
"
bits in the array.
/***************************************************/
MSIE 8.0>>
In some browsers, you can
split
a string on a parenthized delimeter and return the
split-off
bits in the array.
/***************************************************/
MSIE 9.0>>
In some browsers, you can
"
split
"
a string on a parenthized delimeter and return the
"
split-off
"
bits in the array.https://stackoverflow.com/questions/6422355
复制相似问题