从bootstrap-table中的动态添加元素获取元素值 [英] get element value from dynamically added element inside bootstrap-table
问题描述
我有一个引导表和填充/填充数据通过数据库使用JQuery.I动态添加一列(最后一列)元素类型(输入类型='text')。我的问题是,如何获得我在动态添加的输入类型(文本)上输入的数据。
我的引导表:
使用 .val()
而不是 .text()
将事件附加到动态创建的元素。使用 事件委托
。
事件委托允许我们将单个事件监听器附加到
父元素,对于所有匹配
选择器,无论这些后代存在现在还是添加在
的未来。
$(document).on('blur','。input-sm',function(){
var txt = $(this).val();
alert ;
});
I have a bootstrap-table and populated/filled data via database using JQuery.I added a column(last column) element type(input type='text') dynamically. My problem is, how can I get the data I input on dynamically added input type(text).
My reference for my Bootstrap-table: LINK HERE!
Jquery Sample Code:(I tried this, but it gives me NULL
)
$('#accordion-table').on('blur','.input-sm',function() {
var txt = $(this).text();
alert(txt);
});
And also how to get the selected value on OPTION element
and it is dynamic element also.
see sample image below:
Both elements are dynamically added.
Thanks in advance!
use below code to get value from input text box . check DEMO
use .val()
instead of .text()
to attach event to dynamically created element use event delegation
.
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.
$(document).on('blur','.input-sm',function() {
var txt = $(this).val();
alert(txt);
});
这篇关于从bootstrap-table中的动态添加元素获取元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!