所以我有一组这样的事件:
$('#slider-1').click(function(event){
switchBanners(1, true);
});
$('#slider-2').click(function(event){
switchBanners(2, true);
});
$('#slider-3').click(function(event){
switchBanners(3, true);
});
$('#slider-4').click(function(event){
switchBanners(4, true);
});
$('#slider-5').click(function(event){
switchBanners(5, true);
});
Run Code Online (Sandbox Code Playgroud)
我想通过循环运行它们我已经运行了这样的东西:
for(i = 1; i <= totalBanners; i++){
$('#slider-' + i).click(function(event){
switchBanners(i, true);
});
}
Run Code Online (Sandbox Code Playgroud)
理论上应该可以工作,但似乎一旦我加载文档......它没有响应任何特定的div id,就像点击它应该...它进展通过每个div无论我点击哪一个.我想动态创建更多的事件监听器,但我首先需要这些...
我错过了什么?