0
我需要获取每个数据属性中的值并将该值分配给一个变量,然后我想将该变量作为函数中的参数传递(我没有写入该函数或HTML,但必须使用它)。数据属性值是根据不同函数中表的行和列动态生成的。获取相同数据属性的每个值
我想我可以做这样的事情:
priceIndex = $(this).attr("data-priceIndex");
$(this)
是父的TableCell。
然后是priceIndex
变量传递给函数即
<tr><td class="tblProduct selectProduct" data-priceIndex="0_0">
<div class="priceArea" data-priceIndex="0_0">
<button class="okButton origProduct" onclick="goToCart(priceIndex, '', true, false)"></button>
</div>
</td>
<td class="tblProduct selectProduct" data-priceIndex="0_1">
<div class="priceArea" data-priceIndex="0_1">
<button class="upgradeButton upgrdProduct" onclick="goToCart(priceIndex, '', false, false)"></button>
</div>
</td></tr>
但是,这让我对所有data-priceIndex
相同的值。为什么会发生?我怎样才能得到每个数据属性的价值?请告诉我我做错了什么以及如何纠正。谢谢。
。
这看起来很有趣,因为我必须通过其他参数以及获得它们的值(不是硬编码值)。我要试试这个。 – Chris22