从父级获取部分类名并应用于子级 JQuery
我有以下 HTML:
<tr class="wiring_details_6-48">
<td colspan="2"> Wire Type:
<select name="select_wire_6" onchange="Estimate.select_wire( 6, this.value, 0 );">
<option value="" selected="">Select wire..</option>
<option value="1">14/2</option>
<option value="2">14/4</option>
<option value="3">16/4</option>
<option value="4">16/2</option>
<option value="5">RG6</option>
<option value="6">CAT5</option>
<option value="7">RG59</option>
<option value="8">LVT</option>
<option value="9">CAT6</option>
<option value="10">HDMI</option>
<option value="11">Shielded CAT6</option>
</select> </td>
<td colspan="2">Length:
<input type="text" class="id_wire_length_6" name="wire_length_6" value="0"></td>
<td colspan="2">Retail Price:
<input type="text" class="id_wire_retail_6" name="wire_retail_6" value="0"> </td>
<td colspan="2">
<input type="hidden" id="wire_id_6" name="wire_id_6" value="0"> </td>
</tr>
我想确保 input
- id_wire_length
和 id_wire_retail
与其父级相关tr
这可以通过 part-id
得到证明,在本例中是 wiring_details
中的数字 6
和在 id_wire_length
和 id_wire_retail
中。
我的 JS 是:
$('input[class^="id_wire_retail"]').each(function() {
parts_cents_total += (Money.dollars_to_cents($(this).val()) * $('input[class^="id_wire_length"]').val());
});
上面的内容与 id_wire_detail
部分以及 id_wire_length
匹配 - 但我如何确保它是一个与其父级相关,
所以我想这可以归结为:
如何获取父级 tr
的部件号 (6),然后确保上述 JS 仅与输入元素匹配其中 tr
的零件号?
I have the following HTML:
<tr class="wiring_details_6-48">
<td colspan="2"> Wire Type:
<select name="select_wire_6" onchange="Estimate.select_wire( 6, this.value, 0 );">
<option value="" selected="">Select wire..</option>
<option value="1">14/2</option>
<option value="2">14/4</option>
<option value="3">16/4</option>
<option value="4">16/2</option>
<option value="5">RG6</option>
<option value="6">CAT5</option>
<option value="7">RG59</option>
<option value="8">LVT</option>
<option value="9">CAT6</option>
<option value="10">HDMI</option>
<option value="11">Shielded CAT6</option>
</select> </td>
<td colspan="2">Length:
<input type="text" class="id_wire_length_6" name="wire_length_6" value="0"></td>
<td colspan="2">Retail Price:
<input type="text" class="id_wire_retail_6" name="wire_retail_6" value="0"> </td>
<td colspan="2">
<input type="hidden" id="wire_id_6" name="wire_id_6" value="0"> </td>
</tr>
I want to make sure that input
- id_wire_length
and id_wire_retail
are related to their parent tr
this can be proven due to the part-id
which is in this example the number 6
in wiring_details
and in id_wire_length
and id_wire_retail
.
The JS that I have is:
$('input[class^="id_wire_retail"]').each(function() {
parts_cents_total += (Money.dollars_to_cents($(this).val()) * $('input[class^="id_wire_length"]').val());
});
The above matches the id_wire_detail
part as well as the id_wire_length
- but how do I make sure that it is the one related to its parent,
So I guess it comes down to this:
How do I get the parent tr
's part number (6) and then make sure that the above JS matches only input elements with the tr
's part number in them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是这个:
...尝试这个:
这将确保您选择的值是同一
“内部”的值。假设 HTML 结构如您在上面发布的那样,您不必担心按部件号进行匹配。
Instead of this:
...try this:
This will ensure that the value you're selecting is the one "inside" the same
<tr>
. Assuming the HTML structure is as you've posted above, you shouldn't have to worry about matching by part number.