Currently, the function I implemented is implemented as shown in the image below.
Here's the function.
To implement this functionality
I used jequery+js code
(function(){
$(document).ready(function(){
// Gets the index of the last book item.
//(If there are 3 books, the value of 3 is stored in $book_list_num).
$book_list_num = $("div").data("listNum");
for(i=1; i<= parseInt($book_list_num); i++){
//What do you want to know?
var btni = $("#btn"+i)
console.log(btni)
}
});
})();
I wanted to make a button variable as many as the number of buttons generated in html to hold the button and use the onclick method to apply the effect, so I used the repetition statement in the repetition sentence. I'm not sure how to hold it with button+index
.
Please give me some advice.
javascript django jquery
I'm replying to you again.
You can use the evaluation.
eval("var btn" + i + " = '#btn" + i + "';");
I think we can put a variable that specifies the name of btni.
var vname = "#btn"+i;
var btni = $(vname);
© 2024 OneMinuteCode. All rights reserved.