这是一个静态网站可能用到的功能,类似于英语的完形填空,点显示答案按钮以后,可以显示答案在上面,展示如下:
————–代码————– JAVASCRIPT代码部分
<script type="text/javascript"> var hiddenOrShow = 0; function clickMe() { var div = document.getElementById('answerDiv'); var button=document.getElementById('aButton'); if (hiddenOrShow % 2 == 0) { div.style.display = "block"; button.setAttribute("value", "Hide the answer"); } else { div.style.display = "none"; button.setAttribute("value", "Show the answer"); } hiddenOrShow++; } </script>
HTML代码部分
<a>click the button below and you can see the answer in the answer field</a> <br /> <input id="aButton" type="button" value="Show the answer" onclick="clickMe()"> <br> <div> <ul> <li>What's my Name?</li> <li> <div>the answer is:</div> <div id="answerDiv" style="display: none"><a>Moper</a></div> </li> </ul> </div>
(责任编辑:admin) |