簡體   English   中英

動態元素的jQuery onChange

[英]JQuery onChange for Dynamic Elements

我已經審查了類似問題的幾篇文章,但仍未找到解決方法。 我有一張只有一行的表(onLoad)。 單擊一個按鈕,即可向表中動態添加表行(TR)。 然后有一個單獨的腳本為表行分配一個ID。 我有一個onchange腳本,當它更改時,應該給我其中一個元素的ID。 它適用於第一個靜態行。 它不適用於任何動態添加的行。

 $j(".main-wrapper tr:last").after("<tr class='well'><td><div style='display:inline' class='input-group'><select style='display:inline;width:100%'><option value='--None--'>--None--</option><option value='one'>One</option></select></div></td><td><div style='display:inline' class='input-group'><select class='discount-percentage' style='display:inline;width:100%'><option value='--None--'>--None--</option><option value='one'>One</option></select></div></td><td><div class='input-group'><span><input style='display:inline;width:100%' type='text' class='form-control' /></span></div></td><td><div class='input-group'><span><input style='display:inline;width:100%' type='text' class='form-control' /></span></div></td><td><div class='input-group'><input style='display:inline;width:100%' type='text' class='form-control' /></div></td></tr>"); $j(".line-item-table").on("change", 'main-wrapper tr select:first', function() { var dropVal = $j(this).val(); var dropId = $j(this).parent().attr("id"); alert("ID : " + dropId); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

有見識嗎? 我只是在這里俯瞰什么嗎?

 $j(".main-wrapper").on("change", 'tr select', function() { var dropVal = $j(this).val(); var dropId = $j(this).parent().attr("id"); alert("ID : " + dropId); }); 

這對我有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM