gpt4 book ai didi

javascript - 如何使用jquery动态生成的id来获取标签的值

转载 作者:行者123 更新时间:2023-11-28 07:40:04 25 4
gpt4 key购买 nike

我有一个 GridView,其中有两个控件:标签和文本框。我想获取文本框的更改事件上的标签值。

我使用了以下方法来得到这个。但我没有得到值(value)

 $(document).ready(function () {
$('[id$=txtInvoiceInDollar]').change(function (e) {
var textboxid = this.id;

var streetaddress = textboxid.substr(0, textboxid.lastIndexOf('_'));
var exactId = streetaddress + '_lblSaleExt';
var valuetes = $('"#"' + ctl00_ItemMain_grd_Invoice_ctl02_lblSaleExt + '"').val();
alert(valuetes);

return false;
});
});

HTML 代码为:

  <table cellspacing="0" cellpadding="2" border="0" style="border-collapse: collapse;" id="ctl00_ItemMain_grd_Invoice" class="result result-text">
<tbody>
<tr class="head">
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$PricingName')">Pricing Name</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$Variation')">Variation</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$StoreName')">StoreName</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$Quantity')">Quantity</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$ProductID')">Product</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$Descr')">Description</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$SalePrice')">Sale Price</a></th>
<th scope="col">Sale Extended</th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$CostPrice')">Cost Price</a></th>
<th scope="col">Invoice $</th>
<th scope="col">Invoice %</th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$RemainingInDollar')">Remaining $</a></th>
<th scope="col"><a href="javascript:__doPostBack('ctl00$ItemMain$grd_Invoice','Sort$RemainingInPercentage')">Remaining %</a></th>
<th scope="col">Invoice $</th>
<th scope="col">Invoice %</th>
</tr>
<tr class="odd">
<td>Replacement of existing bla bla</td>
<td>True</td>
<td>KFC</td>
<td>2</td>
<td>Prod1</td>
<td>Desc desc</td>
<td>21.32</td>
<td>
<span class="right" id="ctl00_ItemMain_grd_Invoice_ctl02_lblSaleExt">42.64</span>
</td>
<td>18</td>
<td>
<span class="right" id="ctl00_ItemMain_grd_Invoice_ctl02_lblInvoiceInDollar">0</span>
</td>
<td>
<span class="right" id="ctl00_ItemMain_grd_Invoice_ctl02_lblInvoiceInPer">0</span>
</td>
<td>0</td>
<td>0</td>
<td>
<input type="text" class="right" id="ctl00_ItemMain_grd_Invoice_ctl02_txtInvoiceInDollar" value="0" name="ctl00$ItemMain$grd_Invoice$ctl02$txtInvoiceInDollar">
</td>
<td>
<input type="text" class="right" id="ctl00_ItemMain_grd_Invoice_ctl02_txtInvoiceInPer" value="0" name="ctl00$ItemMain$grd_Invoice$ctl02$txtInvoiceInPer">
</td>
</tr>

</tbody>
</table>

请帮我,我怎样才能获得标签的值

最佳答案

谢谢大家,我已经自己解决了。

解决方案如下:

 $('[id$=txtInvoiceInDollar]').change(function (e) {
var textboxid = this.id;

var streetaddress = textboxid.substr(0, textboxid.lastIndexOf('_'));
var exactId = streetaddress + '_lblSaleExt';
var id2 = $("[id$=" + exactId + "]").text();
alert(id2);

return false;
});

感谢您对此问题进行调查。

关于javascript - 如何使用jquery动态生成的id来获取标签的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28167223/

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