[英]Action to element with same id
我需要在与Jquery具有相同ID的项目上调用函数。
我尝试了这个:
$(document).ready(function() {
$('#example').each(function(){
this.dataTable();
});
} );
首先,ID应该是唯一的。 因此,请使用类而不是id。
接下来,您应该绑定jquery以使用该方法:
$(this).dataTable(); // instead of this, use $(this)
$(document).ready(function(){
$('.example').each(function(){
$(this).dataTable();
});
});
Id
不能相同,必须unique
您应该使用class
而不是id
所以
如果为所有必需的元素都提供class="example"
,则可以使用
$(document).ready(function(){
$('.example').each(function(){
$(this).dataTable();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.