首页 > 解决方案 > 从jquery中的一系列值中获取数据

问题描述

我试图根据用户输入的内容获得一系列数字。我有 customer.js,其中包含客户名称和鞋码,我想要根据用户放入的鞋码获得一系列鞋码。

例如。用户输入第一个文本框 5 和第二个文本框 9 我希望显示介于 5 和 9 之间的客户,但也包括 5 和 9。

我只走到这一步。

我的 html

<form id="shoe_size">
    <label for="size">Enter sizes</label>
    <input type="text" name="size1" class="size1">
    <input type="text" name="size2" class="size2">
    <input type="submit" value="Search" class="submit">
</form>

我的jQuery

$('#shoe_size').on('submit', function(){
    var size1 = $('.size1').val();
    var size2 = $('.size2').val();

    $('.table tr').each(function(){
        var size = 'false';
        $(this).each(function(){
            if(size1 <= size2){
                found = 'true';
            }
        })

        if(size == 'true'){
            $(this).show();
        }else{
            $(this).hide();
        }
    });
});

标签: jquery

解决方案


好的,我正在重现您的问题并解决它(因为您的问题不清楚|请给我您的表格,我将尝试根据它进行编码。直到那时我正在使用示例表格)
让我们有一个这样的表格。

table to search

<table>
  <tr size="10" >
    <td>...</td>
    <td>...</td>
  </tr>
  <tr size="11" >
    <td>...</td>
    <td>...</td>
  </tr>
  <tr size="12" >
    <td>...</td>
    <td>...</td>
  </tr>
  <tr size="13" >
    <td>...</td>
    <td>...</td>
    <td>...</td>
  </tr>
  <tr size="14" >
    <td>...</td>
    <td>...</td>
  </tr>
</table>

让用户提交您的表单以获取
任何尺寸范围

Jquery

$('#shoe_size').on('submit', function(){
  var size1 = $('.size1').val();
  var size2 = $('.size2').val();

  $("table tr").each(function(){
     var tr_size = $(this).attr("size");
     if(tr_size >= size1 && tr_size <= size2){
         $(this).show();
     }else{
         $(this).hide();
     }
  });
});

推荐阅读