按类名选择 div
我得到了这个 div...
<div tabindex="0" class="button-base inline-block button aw-btn button-base-active">
<input type="text" tabindex="-1" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow-x: hidden; overflow-y: hidden; position: absolute; ">
</div>
在我的页面中间,它没有 id,我无法编辑页面 HTML,我也无法使用 jQuery。还尝试用 IE7 和 IE8 来实现。
这里是噩梦:)
解决方案是 document.getElementsByClassName 但这与 ie7 和 ie8 不兼容。
这个div被埋在大约10个div中,所有这些div都是相似的风格,没有id等。这个div上的类是独一无二的!
我能看到的唯一解决方案是获取所有 div 并循环它们以查找类似的 hasAttriutes 。
有人有更好的主意吗?
I got this div...
<div tabindex="0" class="button-base inline-block button aw-btn button-base-active">
<input type="text" tabindex="-1" style="opacity: 0; height: 1px; width: 1px; z-index: -1; overflow-x: hidden; overflow-y: hidden; position: absolute; ">
</div>
in the middle of my page, it has no id and I am unable to edit the pages HTML, I am also no able to use jQuery. Also trying to do it with IE7 and IE8.
Nightmare here :)
The solution would be document.getElementsByClassName but that is not ie7 and ie8 compatible.
This div is buried in about 10 divs, all of which are similar style with no id's etc. The classes on this div are unique!
The only solution I can see is to get ALL divs and loop them looking for hasAttriutes similar.
Anyone have a better idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下是针对不兼容浏览器的
getElementsByClassName
的跨浏览器实现 (引用):Here's a cross-browser implementation of
getElementsByClassName
for non-compliant browsers (citation):不,就是这样完成的。除非它们位于带有 ID 的某物中,否则您将不得不迭代页面上的所有 DIV。幸运的是,它只是一个列表(不需要通过树递归),所以它还不错。
Nope, that's how it's done. Unless they're in something with an ID you're stuck iterating all DIVs on the page. Fortunately it is just a list though (no need to recurse through a tree) so it's not so bad.
我建议使用 XPaths 来选择节点。可能有用...
I would suggest using XPaths to select the nodes. Might work...
使用 jQuery/Sizzle。 IE6及以上版本。 :)
加载它:
使用它:
Use jQuery/Sizzle. IE6 and up. :)
Load it:
Use it: