在getElementById内使用变量时遇到麻烦

狂热的

我想转换这些代码:

if(slidedLcount == 0){
        document.getElementById("incredable__offers__examples__item_1").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_2").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_3").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_4").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_5").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_6").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_7").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_8").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_9").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__item_10").style.cssText = "animation-name: SlideL_first;";
        document.getElementById("incredable__offers__examples__arrow__r").classList.remove("grayedout");
    }

这些使它变得更容易,因为会多次使用它:

if(slidedLcount == 0){
        var x = "0";
        var y = "incredable__offers__examples__item_"
        while(x<10){
            var z = y+x;
            document.getElementById(z).style.cssText = "animation-name: SlideL_first;";
            x = (x*1)+1;
        }
        document.getElementById("incredable__offers__examples__arrow__r").classList.remove("grayedout");
    }

但是得到这个错误

mainscript.js:67未捕获的TypeError:无法读取null的属性“样式”

狂热的

感谢您的评论,x应该从1而不是0开始,这是我的愚蠢错误!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用ActionListener更改变量时遇到麻烦

来自分类Dev

使用类型变量显式指定类型时遇到麻烦

来自分类Dev

使用指针时遇到麻烦

来自分类Dev

定义全局变量时遇到麻烦

来自分类Dev

定义全局变量时遇到麻烦

来自分类Dev

ImageMagick在转义shell变量时遇到麻烦

来自分类Dev

我在回声变量时遇到了麻烦

来自分类Dev

使获取数组包含变量时遇到麻烦

来自分类Dev

使用Javascript要求AWS时遇到麻烦

来自分类Dev

使用多个对象时遇到麻烦

来自分类Dev

使用fmod设置setMusicSpeed()时遇到麻烦

来自分类Dev

在使用javascript sort()命令时遇到麻烦

来自分类Dev

Laravel PHP:使用nest()时遇到麻烦

来自分类Dev

使用Jsoup登录网站时遇到麻烦,

来自分类Dev

我在使用BaseAdapter时遇到麻烦

来自分类Dev

使用PHPunit测试代码时遇到麻烦

来自分类Dev

将变量分配给已使用的行数时遇到麻烦

来自分类Dev

使用Django 3将变量从数据库传递到我的网站时遇到麻烦

来自分类Dev

分页时遇到麻烦

来自分类Dev

在类中保留持久变量时遇到麻烦

来自分类Dev

在file_put_contents中声明变量时遇到麻烦

来自分类Dev

使用Github遇到麻烦

来自分类Dev

使用XPATH遇到麻烦

来自分类Dev

在驱动程序类中使用一个类中的变量时遇到一些麻烦

来自分类Dev

我在使用驱动程序类中的一个类中的变量时遇到了一些麻烦

来自分类Dev

在使用解析时使用nil可选遇到麻烦

来自分类Dev

Tilde〜在Mac上使用fstream时遇到麻烦

来自分类Dev

使用Swift初始化属性时遇到麻烦

来自分类Dev

使用多索引处理日期索引时遇到麻烦