Firefox中的getElementsByTagName [英] getElementsByTagName in Firefox

查看:65
本文介绍了Firefox中的getElementsByTagName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有以下代码行在IE中运行良好...


line_1_numbers [0] = document.getElementsByTagName

(''table '')[table_index] .rows(0).cells(0).innerText;


但它是Firefox,它咆哮说:


"错误:document.getElementsByTagName(" table")[table_index] .rows不是

函数"


任何想法意味着什么?


感谢您的帮助,

问候,

Dan。

Hi. I''ve got the following line of code which works fine in IE ...

line_1_numbers [0] = document.getElementsByTagName
(''table'')[table_index].rows (0).cells (0).innerText;

But it Firefox, it barks saying:

"Error: document.getElementsByTagName("table")[table_index].rows is not a
function"

Any ideas what this means?

Thanks for any help,
Regards,
Dan.

推荐答案

Dan写道:
嗨。我有以下代码行在IE中工作正常...

line_1_numbers [0] = document.getElementsByTagName
(''table'')[table_index] .rows (0).cells(0).innerText;

但它是Firefox,它咆哮说:

"错误:document.getElementsByTagName(" table")[table_index ] .rows不是
函数

任何想法意味着什么?

感谢您的帮助,
问候,
丹。
Hi. I''ve got the following line of code which works fine in IE ...

line_1_numbers [0] = document.getElementsByTagName
(''table'')[table_index].rows (0).cells (0).innerText;

But it Firefox, it barks saying:

"Error: document.getElementsByTagName("table")[table_index].rows is not a
function"

Any ideas what this means?

Thanks for any help,
Regards,
Dan.




IE允许您使用()

表示法来处理集合中的索引。改为使用[]。

line_1_numbers [0] = document.getElementsByTagName(''table''

)[table_index] .rows [0] .cells [0]。 innerText;

thing()用于函数。

thing []用于数组/列表。



IE is broken by allowing you to address indices in collections using ()
notation. Use [] instead.
line_1_numbers [0] = document.getElementsByTagName(''table''
)[table_index].rows[0].cells[0].innerText;
thing() is for functions.
thing[] is for arrays/lists.


Christopher J. Hahn写道:

[...]
Christopher J. Hahn wrote:
[...]

通过允许你使用()表示法。改为使用[]。
line_1_numbers [0] = document.getElementsByTagName(''table''
)[table_index] .rows [0] .cells [0] .innerText;

IE is broken by allowing you to address indices in collections using ()
notation. Use [] instead.
line_1_numbers [0] = document.getElementsByTagName(''table''
)[table_index].rows[0].cells[0].innerText;




对innerText的支持是有限的(几乎与IE相同),常规的

表达式可用于从单元格的innerHTML中移除标签到

实现了几乎相同的结果。类似于:

var re = /< [^>] *> / g;


应该可以解决问题。或等待DOM 3得到广泛支持并使用

textContent ;-p


< URL:>

http ://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent>

并非所有浏览器都支持单元格集合(想想

Safari ......)。 childNodes集合可能是更好的选择,并且在这种情况下功能相当于
,因为只有一个单元格(TR | TH)可以是TR的孩子。


var re = /< [^<>] +> / g;

line_l_numbers [0] = ... rows [0]。 childNodes [0] .innerHTML.replace(re,'''');


[...]


-

Rob



Support for innerText is limited (pretty much to IE), a regular
expression can be used to remove tags from the cell''s innerHTML to
achieve pretty much the same result. Something like:
var re = /<[^>]*>/g;

should do the trick. Or wait for DOM 3 to be widely supported and use
textContent ;-p

<URL:>
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent>
The cells collection is not supported by all browsers (think
Safari...). The childNodes collection may be a better choice and is
functionally equivalent in this case as only a cell ( TR|TH ) can be a
child of a TR.

var re = /<[^<>]+>/g;
line_l_numbers[0]=...rows[0].childNodes[0].innerHTML.replace(re,'''');

[...]

--
Rob


RobG写道:
Christopher J. Hahn写道:
[...]
Christopher J. Hahn wrote:
[...]

通过允许您使用()
表示法处理集合中的索引来打破IE。改为使用[]。
line_1_numbers [0] = document.getElementsByTagName(''table''
)[table_index] .rows [0] .cells [0] .innerText;
支持innerText是有限的(几乎是IE)

IE is broken by allowing you to address indices in collections using ()
notation. Use [] instead.
line_1_numbers [0] = document.getElementsByTagName(''table''
)[table_index].rows[0].cells[0].innerText;
Support for innerText is limited (pretty much to IE)




[snip]所有浏览器都不支持单元格集合(想想Safari / ...)。


[snip] -
Rob



[snip] The cells collection is not supported by all browsers (think
Safari...).
[snip] --
Rob



即使我认识他们,我也完全错过了这两点。

这就是为什么我在这里不是一张非常多产的海报。 ;)


Both excellent points that I missed entirely even though I knew them.
This is exactly why I''m not a very prolific poster here. ;)


这篇关于Firefox中的getElementsByTagName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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