【发布时间】:2014-09-05 14:00:07
【问题描述】:
我需要使用 Jquery 对具有相同 ID 的项目调用函数。
我试过这个:
$(document).ready(function() {
$('#example').each(function(){
this.dataTable();
});
} );
【问题讨论】:
标签: javascript jquery css
我需要使用 Jquery 对具有相同 ID 的项目调用函数。
我试过这个:
$(document).ready(function() {
$('#example').each(function(){
this.dataTable();
});
} );
【问题讨论】:
标签: javascript jquery css
【讨论】:
首先,ID 应该是唯一的。因此,请使用 class 而不是 id。
接下来你应该绑定 jquery 以使用该方法:
$(this).dataTable(); // instead of this, use $(this)
$(document).ready(function(){
$('.example').each(function(){
$(this).dataTable();
});
});
【讨论】:
Ids 不能相同,必须是unique
你应该使用class 而不是id
所以
如果您为所有需要的元素提供class="example",那么您可以使用
$(document).ready(function(){
$('.example').each(function(){
$(this).dataTable();
});
});
【讨论】: