gpt4 book ai didi

javascript - 返回数据表输入字段

转载 作者:行者123 更新时间:2023-11-28 18:47:35 24 4
gpt4 key购买 nike

如何返回 jquery 数据表中输入的值?这是我的表格:

<table id="productsTable" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product Code</th>
<th>Brand</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{{#each context}}
<tr>
<td class="product_code">{{product_code}}</td>
<td class="brand">{{brand}}</td>
<td class="category">{{category}}</td>
<td class="description">{{description}}</td>
<td class="price">$ {{invoice_price}}</td>
<td class="quantity"><input type="text"></td> //WANT TO RETURN THIS
<th><a href="/product/{{product_code}}">Details</a></th>
<th><button type="button" class="btn btn-info" style="background-color: #337ab7; border-color: #337ab7">Add to Cart</button></th>
</tr>
{{/each}}
</tbody>
</table>

我特别想通过单击也是该行一部分的按钮来返回此输入中的值:

<td class="quantity"><input type="text"></td>

到目前为止我尝试过:

$(".btn-btn-info").click(function() {
var quantity: $(this).parent().parent().children('td.quantity').val();
console.log(quantity) // returns undefined
}

提前谢谢您!

最佳答案

您可以访问文本框 作为

var quantity = $(this).parents("tr:first").find('.quantity input').val();

关于javascript - 返回数据表输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35052198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com