如何在jquery
中获取被阻止的div idHTML
<div id="USDC1" style="" class="tablegraphview">USDC2</div>
<div id="USDC2" style="display:none" class="tablegraphview">USDC2</div>
<div id="USDC3" style="display:none" class="tablegraphview">USDC3</div>
的Javascript
function tablegraphview(){
var getid = $('.tablegraphview').attr('id');
alert(getid);
}
for ex
<div id="USDC2" style="display:block" class="tablegraphview">USDC2</div>
我需要当前的div id我怎么能在jquery中做到这一点
答案 0 :(得分:3)
尝试使用$(this).is(':visible')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="USDC1" style="" class="tablegraphview">USDC2</div>
<div id="USDC2" style="display:none" class="tablegraphview">USDC2</div>
<div id="USDC3" style="display:none" class="tablegraphview">USDC3</div>
<script>
$(function() {
$(".tablegraphview").each( function(){
if($(this).is(':visible')){
alert($(this).attr("id"));
}
});
});
</script>
或者
根据@pieter命令
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="USDC1" style="" class="tablegraphview">USDC2</div>
<div id="USDC2" style="display:none" class="tablegraphview">USDC2</div>
<div id="USDC3" style="display:none" class="tablegraphview">USDC3</div>
<script>
$(function() {
alert($(".tablegraphview:visible").attr('id'));
});
</script>
&#13;
答案 1 :(得分:0)