我试图根据用户输入的内容获取一系列数字。我有 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();
}
});
});
好的,我正在重新创建您的问题并解决它(因为您的问题不清楚 | 请给我您的表格,我将尝试根据它进行编码。直到那时我正在使用示例表格)
让我们拥有一个这样的表格。
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();
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句