js,获取class,点击没有反应

<!DOCTYPE html>

<html>

<head>


<meta charset="UTF-8">

<title></title>

</head>

<body>

<div class="btn1">dds</div>

<div class="btn1">dds</div>

<div class="btn1">dds</div>

<div class="btn1">dds</div>


<script>


window.onload = function(){

    var btns = document.getElementsByTagName('div')

    for(var i = 0;i<btns.length;i++){

        btns[i].click = function(){

            console.log('i');

            this.innerHTML = "aaa";

        }

    }

}

</script>

</body>

</html>


慕工程0101907
浏览 484回答 1
1回答

白板的微信

把click改成onclick
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript