如果 table 行包含文本,则使用 jquery 数量字段隐藏
Hide with jquery Qty field if the table row contains text
所以我知道这是一件很奇怪的事情,但我正在尝试在 table 的行“Product Name
”中搜索一个短语。
当它找到它时,我想用 title="Qty"
隐藏字段( id
每次都可以不同)
这是我尝试过的:
var thebook = $("tr:contains('Product Name')");
jQuery(thebook).children(input[title='Qty']).hide();
我做错了什么?
input[title='Qty']
应该在引号中,例如 "input[title='Qty']"
没有看到你的完整代码,我不能确定没有其他问题,但这是我使用 .find()
而不是 .children()
搜索所有内容的示例后代链的下行方式:
$("tr:contains('Product B')").find("input[title='Qty']").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>Product A</td>
<td>Quantity: <input title='Qty'></td>
</tr>
<tr>
<td>Product B</td>
<td>Quantity: <input title='Qty'></td>
</tr>
<tr>
<td>Product C</td>
<td>Quantity: <input title='Qty'></td>
</tr>
</table>
所以我知道这是一件很奇怪的事情,但我正在尝试在 table 的行“Product Name
”中搜索一个短语。
当它找到它时,我想用 title="Qty"
隐藏字段( id
每次都可以不同)
这是我尝试过的:
var thebook = $("tr:contains('Product Name')");
jQuery(thebook).children(input[title='Qty']).hide();
我做错了什么?
input[title='Qty']
应该在引号中,例如 "input[title='Qty']"
没有看到你的完整代码,我不能确定没有其他问题,但这是我使用 .find()
而不是 .children()
搜索所有内容的示例后代链的下行方式:
$("tr:contains('Product B')").find("input[title='Qty']").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>Product A</td>
<td>Quantity: <input title='Qty'></td>
</tr>
<tr>
<td>Product B</td>
<td>Quantity: <input title='Qty'></td>
</tr>
<tr>
<td>Product C</td>
<td>Quantity: <input title='Qty'></td>
</tr>
</table>