![](/img/trans.png)
[英]How to get dynamically created javascript div id by jquery and store in php?
[英]How to get ID of dynamically created checkbox javascript jquery
我动态创建了复选框,并使用可以访问所有的类名。
码
$('.checkboxclass').each(function()
{
});
现在我想得到每个复选框的id。 如何相同的任何想法建议?
$('.checkboxclass').each(function()
{
alert($(this).attr('id'));
});
您始终可以使用jQuery对象的attr
方法按名称获取HTML元素的任何属性 。
例如,要检索元素的id:
$(elem).attr('id');
在jQuery each
方法的上下文中,您还可以使用关键字this
访问底层DOM元素。 所以你也可以使用原生JS检索id:
this.id;
尝试以下( 请参阅jsfiddle ):
$('.checkboxclass').each(function() {
alert(this.id);
});
用这个
$(this).attr('id');
在方括号中。
使用Javascript
this.id;
jQuery的
$(this).attr('id');
要么
$(this).prop('id');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.