代码如下,当我把按钮放到div里面的时候,事件无法触发,但把按钮放到div外面,正常,很不能理解,高手指点~
<div style=" width: 200px; height: 160px; background: #0099FF; display: none;" id="dv"><input name="" value="abc" type="button" onclick="document.getElementById('dv').style.display='none';"/>
</body></div>

解决方案 »

  1.   

    <html>
    <body>
    <div style=" width: 200px; height: 160px; background: #0099FF; display: display;" id="dv"><input name="" value="abc" type="button" onclick="document.getElementById('dv').style.display='none';"/>
    </div></body></html>这样写:正常
    经测试,正常没问题
    你再试试
      

  2.   

    <div style=" width: 200px; height: 160px; background: #0099FF; display: none;" id="dv"><input name="" value="abc" type="button" onclick="this.parentNode.style.display='none';"/></div>
      

  3.   

    lschema,似乎display是一个无效的值啊,根据你的启发,我尝试了一下,只要不设display的值,就可以工作,但随之而来的问题是:我如何让这个层再次显示?如果将display属性设为block或置空,又无法隐藏层了。
    另,2楼,那是笔误,嘿嘿
      

  4.   

    真相大白了=。=
    <div style=" width: 200px; height: 160px; background: #0099FF; " id="dv"><input name="" value="abc" type="button" onclick="document.getElementById('dv').style.display='none';"/>
    </div>
    <div style=" width: 200px; height: 10px; background: #0099FF;" onmouseover="document.getElementById('dv').style.display='block';"> 
    </div>
    设想的效果是,点按钮隐藏第一个层,鼠标移到第二个层显示第一个层,因为在隐藏第一个层的时候,第二个层的位置上移,而鼠标还在那里,又马上触发了显示第一个层的事件,由于执行速度太快,导致像隐藏第一个层不起作用一样。中间加几个<br>,马上OK了