您好,我只想在 ProductPriceRating 类中显示第一个 div 测试,我想隐藏其余的 div。任何人都可以帮助我。
<div class="ProductPriceRating">
<strong>$47.00</strong>
<div class="test"><input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com">
<div class="test"><input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com"></div>
<div class="test"><input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com"></div>
<div class="test"><input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com"></div>
<div class="test"><input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com"></div>
</div>
最佳答案
你错过了</div>
首先.test
你的代码将是
$(document).ready(function() {
$('.ProductPriceRating .test:first-of-type').addClass('active');
})
.test {
display: none;
}
.test.active {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="ProductPriceRating">
<strong>$47.00</strong>
<div class="test">
<input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com">
</div>
<div class="test">
<input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com1">
</div>
<div class="test">
<input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com">
</div>
<div class="test">
<input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com">
</div>
<div class="test">
<input type="button" class="btn" id="hello_123" onclick="window.open('1234')" value="test.com">
</div>
</div>
每页不要多次使用相同的 ID!
关于javascript - 想要使用 Jquery 在 <div> 中仅显示第一类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34369826/