简体   繁体   English

当只有一个内容时隐藏引导轮播指示器

[英]Hide bootstrap carousel indicators when there is only one content

I've seen many examples in different languages but nothing with JavaScript/JQuery.我见过很多不同语言的例子,但没有 JavaScript/JQuery 的例子。

I currently build my Carousel in my JS from my XML file, where I declare img path etc. Now I have the issue that my Carousel contain just one image sometimes and if that's so, I want to hide my carousel-control and my carousel-indicators我目前从我的 XML 文件在我的 JS 中构建我的 Carousel,我在其中声明了 img 路径等。现在我的 Carousel 有时只包含一个图像,如果是这样,我想隐藏我的 carousel-control 和我的 carousel-指标

How can I check in JS if there is more than one Image?如果有多个图像,我如何签入 JS?

在此处输入图像描述

First, you should have a class attribute for the images in your carousel, then you use the getElementsByClassName to save the image into an array, and you will get all your images.首先,您应该为轮播中的图像设置 class 属性,然后使用 getElementsByClassName 将图像保存到数组中,您将获得所有图像。

 let myImg = document.getElementsByClassName("your-image-in-carousel") console.log(myImg)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM