Example of a response event

Source: Internet
Author: User

Example 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>
Example 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)">
Example 3 counter (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>



From for notes (Wiz)



Example of a response event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.