zoukankan      html  css  js  c++  java
  • 响应事件的示例

    示例 1 onmousedown, onmouseup

    1. <script>
    2. function textcolor(cursor, i){
    3. if(i ==0)
    4. cursor.style.color ="#0000FF";
    5. else
    6. cursor.style.color ="#E7D745";
    7. }
    8. </script>
    9. <h2 onmouseup="textcolor(this,1)"
    10. onmousedown="textcolor(this,0)">
    11. 按下、松开颜色改变的文本
    12. </h2>
     
     
    示例 2 onmouseover,onmouseout
    1. <script>
    2. function changeImage(img, i){
    3. if(i ==0)
    4. img.src ="images/temp0.jpg";
    5. else
    6. img.src ="images/temp1.jpg";
    7. }
    8. </script>
    9. <img src="images/temp0.jpg" border="0" width="200" height="220"
    10. onmouseOver="changeImage(this,1)"
    11. onmouseOut="changeImage(this,0)">
     
    示例3  计数器(countdown)
    1. <div id="container">
    2. <div id="inputArea">
    3. </div>
    4. <h1 id="time">0:00</h1>
    5. </div>
    6. <script>
    7. // two global variables
    8. var secondsRemaining;
    9. var intervalHandle;
    10. function resetPage(){
    11. document.getElementById("inputArea").style.display ="block";
    12. }
    13. function tick(){
    14. // grab the h1
    15. var timeDisplay = document.getElementById("time");
    16. // turn seconds into mm:ss
    17. var min =Math.floor(secondsRemaining /60);// floor功能: 返回比参数小的最大整数
    18. var sec = secondsRemaining -(min *60);
    19. // add a leading zero (as a string value) if seconds less than 10
    20. if(sec <10){
    21. sec ="0"+ sec;
    22. }
    23. // concatenate with colon
    24. var message = min +":"+ sec;
    25. // now change the display
    26. timeDisplay.innerHTML = message;
    27. // stop if down to zero
    28. if(secondsRemaining ===0){
    29. alert("Done!");
    30. clearInterval(intervalHandle);
    31. resetPage();
    32. }
    33. // subtract from seconds remaining
    34. secondsRemaining--;
    35. }
    36. function startCountdown(){
    37. // get contents of the "minutes" text box
    38. var minutes = document.getElementById("minutes").value;
    39. // check if not a number
    40. if(isNaN(minutes)){
    41. alert("Please enter a number!");
    42. return;
    43. }
    44. // how many seconds?
    45. secondsRemaining = minutes *60;
    46. // every second, call the "tick" function
    47. intervalHandle = setInterval(tick,1000);
    48. // hide the form
    49. document.getElementById("inputArea").style.display ="none";
    50. }
    51. // as soon as the page is loaded...
    52. window.onload =function(){
    53. // create input text box and give it an id of "minutes"
    54. var inputMinutes = document.createElement("input");
    55. inputMinutes.setAttribute("id","minutes");
    56. inputMinutes.setAttribute("type","text");
    57. // create a button
    58. var startButton = document.createElement("input");
    59. startButton.setAttribute("type","button");
    60. startButton.setAttribute("value","Start Countdown");
    61. startButton.onclick =function(){
    62. startCountdown();
    63. };
    64. // add to the DOM, to the div called "inputArea"
    65. document.getElementById("inputArea").appendChild(inputMinutes);
    66. document.getElementById("inputArea").appendChild(startButton);
    67. };
    68. </script>
     
     





  • 相关阅读:
    固态硬盘安装后优化
    如何在面试中为人才留下好印象
    数据化管理学习笔记
    项目经理入门记(一)
    Ubuntu10下MySQL搭建Amoeba系列(文章索引)
    SQL Server 性能优化实战系列(文章索引)
    Ubuntu12下挂载硬盘(9TB)(文章索引)
    SQL Server 设计开发系列(文章索引)
    简单实用SQL脚本
    SQL Server 维护管理系列(文章索引)
  • 原文地址:https://www.cnblogs.com/Jener/p/5984680.html
Copyright © 2011-2022 走看看