如何根据其样式找到div元素?
我在IE6中“查看源代码”并拥有:
...an><div id="lga" style="height:231px;margin-top:-22px"><img alt="Google"...
如何在JavaScript中获取此内容?
答案 0 :(得分:0)
问题不是很清楚。这是你在找什么?
var div_style = document.getElementById('lga').style;
答案 1 :(得分:0)
为什么你想通过它的风格得到div?通过它的ID来获取它会简单得多。
标准JavaScript:
document.getElementById("lga");
如果使用jQuery:
$("#lga");
答案 2 :(得分:0)
document.getElementById("lga");
答案 3 :(得分:0)
如果你真的想按照它的风格找到元素(我不推荐)
通过jQuery做到这一点
// jQuery attr equal value selector [1]
$('[style="{your_style_value}"]');
// in your case
$('[style="height:231px;margin-top:-22px"]')
[1] http://api.jquery.com/attribute-equals-selector/
希望这有帮助:)
答案 4 :(得分:0)
真正的WTF是你正在使用Internet Explorer 6,即使Internet Explorer 8是Windows 7,Internet Explorer 9及以上版本9的标准,即使你有旧版本的Windows仍然有firefox和Chrome这是> Internet Explorer 6。