jquery - 从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();
}
});
});
解决方案
好的,我正在重现您的问题并解决它(因为您的问题不清楚|请给我您的表格,我将尝试根据它进行编码。直到那时我正在使用示例表格)
让我们有一个这样的表格。
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();
}
});
});
推荐阅读
- c# - C#通过OleDBDataReader从大型excel文件批量复制抛出内存异常
- html - 如何使我的 CSS 边框仅围绕我的链接?
- javascript - 使用函数设置 JavaScript 对象属性
- python - 姜戈 1.8。当我们在值中使用 id 字段并在 django 中注释操作时,结果 sql-query 中会忽略其他字段
- javascript - 将脚本添加到加载主体后运行的头部
- php - 如何将2个选择元素组合在一起html
- visual-studio-code - vs code 孪生页面图标消失了
- excel - 宏优化 ifs 似乎减慢了 lat
- node.js - 使用图像格式将图像保存到 s3 存储桶
- c++ - 使用重载运算符添加构造函数