javascript - 想要使用 Jquery 在 <div> 中仅显示第一类

标签 javascript jquery html css

您好,我只想在 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/

相关文章:

php - 如何使用 PHP 显示数据库中的图像?

javascript - Angularjs - 整个应用程序加载后如何运行代码?

javascript - setInterval 和clearInterval 问题?

javascript - 几次循环后函数就被破坏了

JavaScript:如何将额外参数传递给回调

JavaScript 正则表达式 : Replace spaced substring from the string

javascript - 通过 JavaScript 单击消防按钮

javascript - 单击<a>标签时如何防止页面刷新?

javascript - 使用 JavaScript 动态编辑 Base64 编码图像

php - Laravel 中的 Bootstrap 模态验证