我有一个隐藏的div的集合,我只用一个类名(class =" asd")。 .text()方法似乎不起作用,即使是通过filter方法返回一个对象。其他JQuery方法仍然无法正常工作。 那是我的代码:
<script>
$(document).ready(function(){
alert($("#vetrina > :hidden").filter(".asd").text());
});
</script>
HTML:
<div id="vetrina">
<div class="blocco" class="1">
the text i don't need
</div>
<div class="blocco-inv" class="asd">
THE TEXT I WOULD GET
</div>
<div class="blocco-inv" class="3">
the text i don't need (it is still hidden)
</div>
</div>
和CSS:
<style>
#vetrina{
width: 100%;
background-color: none;
display: table-row;
}
.blocco{
display: table-cell;
margin: 15px;
border: 2px solid lightgrey;
position: absolute;
display: inline;
}
.blocco-inv{
display: table-cell;
margin: 15px;
border: 2px solid lightgrey;
position: absolute;
display: none;
}
</style>
答案 0 :(得分:0)
$(document).ready(function(){
alert($(".asd").text());
});
#vetrina{
width: 100%;
background-color: none;
display: table-row;
}
.blocco{
display: table-cell;
margin: 15px;
border: 2px solid lightgrey;
position: absolute;
display: inline;
}
.blocco-inv{
display: table-cell;
margin: 15px;
border: 2px solid lightgrey;
position: absolute;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="vetrina">
<div class="blocco 1">
the text i don't need
</div>
<div class="blocco-inv asd">
THE TEXT I WOULD GET
</div>
<div class="blocco-inv 1">
the text i don't need (it is still hidden)
</div>
</div>