Here's the HTML
<li class="carousel-btn-wrapper">
<div class="progressButton">
<p></p>
</div>
<button class="videoCaroselButton">Welcome</button>
</li>
<li class="carousel-btn-wrapper">
<div class="progressButton">
<p></p>
</div>
<button class="videoCaroselButton">Video Name</button>
</li>
<li class="carousel-btn-wrapper">
<div class="progressButton">
<p></p>
</div>
<button class="videoCaroselButton">Another Video Name</button>
</li>
I am trying to add a number in the p tag that is a child of the .progressButton. I need the number to increase with every p tag. I'm having issues with my javascript loop. I assume the issue is in the way .text(buttonNumber[]); is indexing. How do I solve this?
var videoSrcArray = ['url.com/adf', 'url.com/asf', 'url.com/sdf', 'url.com/asdf','url.com/asdfl']
var buttonNumber = "";
var i;
for (i = 1; i < videoSrcArray.length - 1; i++) {
buttonNumber += i ;
$('.progressButton').children('p').text(buttonNumber[1]);
}
You actually don't need buttonNumber
at all. Delete it (lines 2 and 5) and then change:
$('.progressButton').children('p').text(buttonNumber[1]);
to:
$('.progressButton').children('p').eq(i-1).text(i);
尝试使用init buttonNumber为0.然后,使用var初始化你的for循环的i,然后使用buttonNumber.toString()而不是buttonNumber []
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.