eTarget.id.style.display = 'none' not working

eTarget.id.style.display = 'none' not working

本文关键字:none not working id style eTarget display      更新时间:2023-09-26

我想在点击时使用HTML代码后面的脚本隐藏这个div,但它似乎不工作,虽然在代码之间添加alert(ettarget .id)返回div id specc。如果我简单地替换事件。在脚本中使用specsC,它工作得很好。

<div class = 'tile1c' id='specsC' onclick='hide()'>
    <h3>Specifications</h3>
</div>
<script type='text/javascript'>
function hide(e){
    if(!e)
        e = window.event;
    eTarget = e.target || e.srcElement;
    eTarget.id.style.display = 'none';
    }
<script>

Try just:

eTarget.style.display = 'none';

id不应该在那里。

eTarget.id解析为字符串"specsC"