按类名选择div
我得到了这个div ......
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>
在我的页面中间,它没有ID,我无法编辑页面HTML,我也无法使用jQuery。还试图用IE7和IE8来做。
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.
这里的梦魇:)
解决方案是文档。 getElementsByClassName但不是ie7和ie8兼容。
The solution would be document.getElementsByClassName but that is not ie7 and ie8 compatible.
这个div埋藏在大约10个div中,所有这些都是类似的样式,没有id等等。这个div上的类是唯一的!
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!
我能看到的唯一解决方案是获取所有div并循环查找hasAttriutes类似。
The only solution I can see is to get ALL divs and loop them looking for hasAttriutes similar.
任何人都有更好的主意吗?
Anyone have a better idea?
这是 getElementsByClassName $的跨浏览器实现c $ c>适用于不兼容的浏览器(引用):
Here's a cross-browser implementation of getElementsByClassName
for non-compliant browsers (citation):
if (!document.getElementsByClassName)
{
document.getElementsByClassName = function(classname)
{
var elArray = [];
var tmp = document.getElementsByTagName("*");
var regex = new RegExp("(^|\\s)" + classname + "(\\s|$)");
for ( var i = 0; i < tmp.length; i++ ) {
if ( regex.test(tmp[i].className) ) {
elArray.push(tmp[i]);
}
}
return elArray;
};
}