我在网页上有两个 div,需要从页面加载中隐藏它们,直到脚本块中的 if 语句指示何时显示 div..这可能吗?怎么做?我有一个 jQuery 链接,但我尝试过的不起作用
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
background-color: #3da9cd;
background:url('background.jpg');
height: 50%;
width: 50%;
margin:0;
padding: 0;
overflow:auto;
}
h1 {
font-size: 34px;
margin: 0;
padding: 0;
font-family: Georgia, "Times New Roman", Times, serif;
font-weight: bold;
color: #000000;
.hidden { display: none; }
.shown {display:block;}
}
</style>
<script type="text/javascript">
function WinLose()
{
$("#win").hide();
$("#lose").hide();
var x=document.getElementById("demo");
x=x.innerHTML=Math.floor((Math.random()*5)+1);
if (x==5)
{
$('#win').show()
}
else
{
$('#lose').show()
}
}
</script>
</head>
<body>
<p id="demo"></p>
<button onclick="WinLose()">Try it</button>
<!-- Win element -->
<div id="win" class="hidden">Congratulations! You have won a prize. *UNIQUE CODE* Collect your prize from the Customer Services desk</div>
<!-- The losing image div -->
<div id="lose" class="hidden">Sorry, you have not won. Better luck next time</div>
</body>
</html>