SoFunction
Updated on 2025-04-10

JS index index index li collection binding click event

The following code introduces the li collection binding click event. The specific code is as follows:

//Method-1:
var items = ('li');
for(var i=0;i<;i++){
items[i].index = i;
items[i].onclick = function(){
 = ;
}
}
//Method-2:
var items = ('li');
for(var i = 0; i<; i++){
(function(index){
items[i].onclick = function(){
 = index;
}
})(i)
}
//Method-3:
var items = ('li');
for(var i = 0; i<; i++){
items[i].onclick = function(index){
return function(){
 = index;
}
}(i)
}

Summarize

The above is the li collection binding click event introduced by the editor to you by the js index index subscript. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!