这个java script代码没有报错,不能运行?哪儿出错了?谁来告诉我谢谢!

新手上路,请多包涵

<!doctype html>
<html lang="en">
<head>

<meta charset="UTF-8">
<title>Document</title>
<style>
    *{
        margin: 0;
        padding: 0;
    }
    #wrapper{
        width: 250px;
        margin: 75px auto;
    }
    #wornContent{
        width: 240px;
        height: auto;
        background-color: #ccc;
        border: 1px solid #888;
        padding: 5px;
        display: none;
    }
</style>

</head>
<body>

<div id="wrapper">
    <input type="checkbox" title="" id="worn">
    <div id="wornContent">为了你信息的安全,请在公共场所或网吧不要用此功能</div>
</div>
<script>
    function showHide(attr)
    {
        var oWornContent = document.getElementById('wornContent');
        oWornContent.style.display =attr;
    }
    var oWorn = document.getElementById('worn');
    oWorn.onmouseover = showHide('block');
    oWorn.onmouseout = showHide('none');
</script>

</body>
</html>

阅读 2.8k
3 个回答
 oWorn.onmouseover = function(){showHide('block')};
 oWorn.onmouseout = function(){showHide('none');}

ele 要用adeventlisener

onmouseover、onmouseout需要绑定的是函数,而你通过这种方式写,相当于是绑定了一个函数的执行结果;
而对于showHide函数来说没有显式的指定return,那么返回值也就是undefined,就相当于绑定了undefined;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题