热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

做文档。getElementsByTagName改变工作?-doesdocument.getElementsByTagNameworkinvbscript?

Well,itworks,itjustdoesntproduceanythingworthwhile:它起作用了,但没有产生任何有价值的东西:elemsdocument

Well, it works, it just doesn't produce anything worthwhile:

它起作用了,但没有产生任何有价值的东西:

elems = document.getElementById("itemsTable").getElementsByTagName("TR") 
for j = 0 to ubound(elems) - 1      
   ' stuff 
next

Well, that won't work, apparently elems is an object, not an array like you'd get in that fancy Javascript. I'm stuck with Vbscript though.

这行不通,显然elems是一个对象,而不是像Javascript那样的数组。但是我被Vbscript困住了。

So what do I do to iterate all the rows in a table in Vbscript?

那么,我要如何遍历Vbscript中的表中的所有行呢?

Edit: Yes, it's Vbscript and it sucks. I don't have a choice here, so don't say "Use jQuery!!".

编辑:是的,是Vbscript,很烂。我在这里没有选择,所以不要说“使用jQuery!!”

3 个解决方案

#1


7  

As you have correctly stated getElementsByTagName does not return an array, hence UBound() will not work on it. Treat it as a collection.

正如您正确地声明了getElementsByTagName不返回数组,因此UBound()不会对它起作用。把它当作收藏品。

For-Eaching through it should work:

通过它进行操作应该是有效的:

 Set NodeList = document.getElementById("itemsTable").getElementsByTagName("TR") 
 For Each Elem In NodeList
  ' stuff 
  MsgBox Elem.innerHTML
 Next

#2


1  

If you have IE8+, you can use the "item" method. So it'd be:

如果你有IE8+,你可以使用“item”方法。所以它会:

Dim elem: Set elem = document.getElementById("itemsTable").getElementsByTagName("TR").item(1);

#3


0  

elems isn't an array in Javascript either, it is a NodeList, it just happens to share some properties with a Javascript Array object.

elems也不是Javascript中的数组,它是NodeList,它只是碰巧与Javascript数组对象共享一些属性。

I don't know VB, but I assume you could do:

我不知道VB,但我想你可以:

for j = 0 to elems.length - 1      
   ' stuff 
next

推荐阅读
author-avatar
Genesis Gaming
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有