仅当class="center outstanding"
包含文字.small
时,才需要使用XYZ
删除td中的表单按钮。我正在使用下面的代码,但它只删除第一个实例并停止。非常感谢任何帮助!
if ($("div.subtle:contains('XYZ')").length) {
$('#pay').hide();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="accounts" class="billing">
<tbody>
<tr title="Details">
<td class="tblLeft">
<div class="small">ABC Company</div>
</td>
<td class="center outstanding">$0.00</td>
</tr>
<tr title="Details">
<td class="tblLeft">
<div class="small">XYZ Company</div>
</td>
<td class="center outstanding">$161.47<br />
<form autocomplete="off" method="post" action="/paythebill.asp" id="payaccountform"><input class="button completeworkflow" type="submit" name="pay" id="pay" value="Pay" title="" /></form>
</td>
</tr>
<tr title="Details">
<td class="tblLeft">
<div class="small">XYZ Company</div><br /></td>
<td class="center outstanding">$0.00<br /></td>
</tr>
<tr title="Details">
<td class="tblLeft">
<div class="small">ABC Company</div>
</td>
<td class="center outstanding">$122.88<br />
<form autocomplete="off" method="post" action="/paythebill.asp" id="payaccountform"><input class="button completeworkflow" type="submit" name="pay" id="pay" value="Pay" title="" /></form>
</td>
</tr>
</tbody>
</table>
答案 0 :(得分:1)
要实现此目的,您可以使用:contains
查找相关的.small
元素,然后遍历DOM以查找同一form
和{{}内的相关tr
元素1}}它。试试这个:
hide()
$('.small:contains("XYZ")').closest('tr').find('form, br').hide()
另请注意,您在HTML中重复了<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="accounts" class="billing">
<tbody>
<tr title="Details">
<td class="tblLeft">
<div class="small">ABC Company</div>
</td>
<td class="center outstanding">$0.00</td>
</tr>
<tr title="Details">
<td class="tblLeft">
<div class="small">XYZ Company</div>
</td>
<td class="center outstanding">$161.47<br />
<form autocomplete="off" method="post" action="/paythebill.asp" id="payaccountform"><input class="button completeworkflow" type="submit" name="pay" id="pay" value="Pay" title="" /></form>
</td>
</tr>
<tr title="Details">
<td class="tblLeft">
<div class="small">XYZ Company</div><br /></td>
<td class="center outstanding">$0.00<br /></td>
</tr>
<tr title="Details">
<td class="tblLeft">
<div class="small">ABC Company</div>
</td>
<td class="center outstanding">$122.88<br />
<form autocomplete="off" method="post" action="/paythebill.asp" id="payaccountform"><input class="button completeworkflow" type="submit" name="pay" id="pay" value="Pay" title="" /></form>
</td>
</tr>
</tbody>
</table>
和pay
payaccountform
个属性。 id
必须是唯一的。我建议将它们更改为类或在不需要时删除它们。