简体   繁体   English

我不知道为什么我的代码是错误的? 有什么问题吗?

[英]I dont know why my code is wrong ? and what wrong is it?

document.getElementById("link1").addEventListener("click", c);
    function c(){
        var a = document.querySelectorAll('.images');
        for(var k in a){
            a[k].setAttribute('class','col-md-12');
        }
    }
document.getElementById("link2").addEventListener("click", d);
    function d(){
        var a = document.querySelectorAll('.images');
        for(var k in a){
            a[k].setAttribute('class','col-md-6');
        }
    }   
document.getElementById("link3").addEventListener("click", e);
    function e(){
        var y = document.querySelectorAll('.images');
        for(var z in y){
            y[z].setAttribute('class','col-md-4');
        }
    }   

here is my JS code , i dont know what im wrong ?这是我的 JS 代码,我不知道我错了什么? anyone can help ?任何人都可以帮忙吗? thanks a lot:) my demo in codepen http://codepen.io/anon/pen/MyRmGy非常感谢:) 我在 codepen 中的演示http://codepen.io/anon/pen/MyRmGy

By changing the class attribute of the images, they will not be found by subsequent calls to document.querySelectorAll('.images')通过更改图像的class属性,它们将不会被后续调用document.querySelectorAll('.images')

Set a class attribute that maintains the images class:设置维护images类的类属性:

a[k].setAttribute('class', 'col-md-12 images');

(If your issue is that the code only works on first link click; you haven't said) (如果您的问题是代码仅适用于第一次链接点击;您没有说)

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

相关问题 我是 ajax 和 jquery 的新手,所以我不知道我的代码有什么问题 - i am new to ajax and jquery so i dont know what is wrong in my code 我想让它成为一个全局变量,但我不知道我做错了什么替换图像 src 代码 - I want to make this a global variable but I dont know what Im doing wrong replacing image src code 我知道此代码无法正常工作,为什么我找到的代码可以工作? 是什么使错误的代码错了? - I know this code does not work, why does the code that I found does? What makes the wrong code, wrong? 学校作业,我不知道我做错了什么 - School assignment, i dont know what im doing wrong 我的减速器 function 没有显示我在反应中获取的数据。 我不知道我做错了什么 - My reducer function is not displaying the data I'm fetching in react. i dont know what im doing wrong 我已经尝试使用ajax调用我的PHP函数,但我不知道它的代码错误是什么不起作用 - I have tried using ajax to call into my php function but i dont know whats wrong with the code its not working 我的 p5.js 代码滞后我不知道为什么? - My p5.js code is lagging i dont know why? 我的代码有什么问题? - What is wrong with my code? 我的代码有什么问题? - What is wrong in my code? 试图更改活动标签颜色,不知道我在代码中做错了什么 - Trying to change active tab color, don't know what I am doing wrong in my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM