如何获取当前行的select选项的值
How do I get value of select option for current row
我有动态字段来生成选择选项&文本输入。
var i=$('table tr').length;
$(".addmore").on('click',function(){
html = '<tr>';
html += '<td><select name="itemType[]" id="itemType_'+i+'" class="form-control input-sm"><option value="AAA">AAA</option><option value="BBB">BBB</option></select></td>';
.....
.....
html += '</tr>';
$('table').append(html);
i++;
});
$(document).on('focus','.autocomplete_txt',function(){
type = $(this).data('type');
if(type =='itemName' )autoTypeNo=0;
$(this).autocomplete({
source: function( request, response ) {
$.ajax({
url : 'ajax',
dataType: "json",
method: 'post',
data: {
search : request.term,
type : type,
select : $("#itemType_"+i).val()
}
success: function( data ) {}
..
为什么$("#itemType_"+i).val()
返回空值?我这里少了什么?
因为当前的select
将有一个id
,比如itemType_7
,但i
的值将是8
,因为您在创建select
后递增它。
因此,在获取您创建的最新select
的值时,您应该执行
$("#itemType_"+(i-1)).val()
相关文章:
- 根据select选项元素将表单重定向到不同的URL
- jQuery动态表单显示在select选项上
- 如何在触发事件后选择select选项
- jQuery:根据select选项中的每页项目进行分页
- 使用JavaScript删除多个select选项
- 使用select选项转换时间.使用javascript
- 使用angularjs解析JSON,并选择select选项
- 使用jQuery在select选项上设置HTML数据属性
- 如何防止onclick事件在select选项中触发
- 如何在angular js中的select选项中获取所选项目id
- ng-select 选项在与自定义指令一起使用时加倍
- jQuery未能将JSON数据附加为select选项
- 如何将html中select选项的输入与javascript一起使用
- 使用VueJs获取Select选项文本
- 从jquery中的select选项添加两个不同的数组值(text&value)
- select选项在angularjs中不显示
- jQuery v 1.1x更改select选项的值
- 将select选项添加到id中
- 基于select选项的javascript动态表单生成
- Select选项包含在验证模型MVC时不起作用