问答详情
源自:3-6 控制类名(className 属性)

为什么这段getElementsByClassName没有效果,而换成getElementByID就有效果了

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>mapDr2</title>
    <style>
 .btns_mapDr{
            color: red;
 border-color: #66ccff;
 border-style:dotted;
 border-width:3px;
 }
        .btns_mapDr:hover{
            cursor: pointer;
 }
    </style>
</head>
<body>
<table>
    <tr>
        <td class="btns_mapDr mapDrbili" id="mapDrbili"  mapURL-data="http://www.bilibili.com/video/kichiku.html">鬼畜区</td>
        <td class="btns_mapDr mapDracfun" id="mapDracfun"  mapURL-data="http://www.bilibili.com/video/teleplay.html">影视区</td>
    </tr>
</table>
<iframe id="mapFrame" width="100%" height="800" src ="https://www.bilibili.com/"></iframe>
</body>
<script type="text/javascript">
 var btns = document.getElementsByClassName("btns_mapDr");
 btns.onclick = function () {
        alert("hello");

 }
</script>
</html>


提问者:jdlight0920 2015-12-28 14:54

个回答

  • 阳_fqBVX7
    6天前

    因为你这个还没有获取id