簡體   English   中英

使用> =會給出錯誤的結果?

[英]Using >= gives incorrect results?

我有2張桌子,每張桌子有10行。 有兩個下拉菜單。 第一個數字為1-10,第二個數字為11-20。

現在,第1-10行都屬於同一類,而11-20行則屬於同一類。

問題是,假設我只選擇第二個下拉列表並選擇“ 13”,它應該只給我編號為“ 11-13”的行,而不是編號為“ 1-10”的行。 當前,如果我從第二個下拉列表中選擇一個值,它也會自動顯示1-10行。 它不應該這樣做。

類別為<tr class="input-containers Container1"></tr>容器行的第一個循環,直到<tr class="input-containers Container10"></tr>

<script>
$(document).ready(function() {
  function hideAllContainers() {

    $(".input-containers").hide();
    $("#input-containers").show();
  }
  //#containers is the dropdown with options 1-10
  $('#containers').on('change', function() {

    hideAllContainers();
    var count = parseInt(this.value);

    for (i = 1; i <= count; i++) {
    console.log($(".Container" + i));
      $(".Container" + i).show();
    }
  });
});
</script>

類別為<tr class="input-secondcontainers Container11"></tr>容器行的第二個循環,直到<tr class="input-secondcontainers Container20"></tr>

<script>
$(document).ready(function() {
  function hideAllContainers2() {

    $(".input-secondcontainers").hide();
    $("#input-secondcontainers").show();

  }
  //#containers2 is the dropdown with options 11-20
  $('#containers2').on('change', function() {

    hideAllContainers2();
    var count = parseInt(this.value);

    for (i = 1; i >= count; i++) {
    console.log($(".Container" + i));
      $(".Container" + i).show();
    }
  });
});
</script>

在第二個for循環上嘗試以下操作:

 $('#containers2').on('change', function() {

    hideAllContainers2();
    var count = parseInt(this.value);

    for (i = 11; i <= count; i++) {
    console.log($(".Container" + i));
      $(".Container" + i).show();
    }
  });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM