三目运算符

<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
    #div1 {
        width: 100px;
        height:100px;
        background: red;
        display: none;
    }
</style>
</head>

<body>
<script>
    function showhide()
    {
        var odiv=document.getElementById('div1');
        odiv.style.display=='block'?odiv.style.display='none':odiv.style.display='block';
    }
</script>
<input type="button" value="显示隐藏" onClick="showhide()" />
<div id="div1">
    
</div>
</body>
</html>

查看原文

posted @ 2017-11-24 20:44  绿林豪士  阅读(267)  评论(0编辑  收藏  举报