js click event

After the mouse event when the mouse moves over an object, the object will trigger onclick event and execute onclick Event call.

Reality mouse click

window.onload = function () {


var nav=document.getElementsByClassName("nav")
var acc = document.getElementsByClassName('acc');
var bg_a = document.getElementsByClassName('bg_a');

for (var i=0;i<acc.length;i++) {
        acc[i].index = i;
        acc[i].onclick = function () {
            console.log(bg_a)
            for (var i=0;i<acc.length;i++) {
                bg_a[i].style.display = 'none';
                console.log(bg_a)
            }
            bg_a[this.index].style.display = 'block'
            console.log(bg_a)
        }
}
}

 

When the button to trigger onclick event,

Guess you like

Origin www.cnblogs.com/LQK157/p/11027030.html