focushandler.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.events.FocusHandler</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.dom');
  13. goog.require('goog.events');
  14. goog.require('goog.events.FocusHandler');
  15. </script>
  16. <link rel="stylesheet" href="css/demo.css">
  17. </head>
  18. <body>
  19. <h1>goog.events.FocusHandler</h1>
  20. <p>i1: <input id=i1>
  21. <p>i2 <input id=i2>
  22. <p>i3: <input id=i3>
  23. <p id=out>
  24. <script>
  25. var $ = goog.dom.getElement;
  26. function updateText(e) {
  27. var target = e.target;
  28. $('out').appendChild(document.createTextNode(target.tagName + "#" +
  29. target.id + ": " + e.type));
  30. $('out').appendChild(document.createElement('br'));
  31. }
  32. var focusHandler = new goog.events.FocusHandler(document.body);
  33. goog.events.listen(focusHandler, goog.events.FocusHandler.EventType.FOCUSIN,
  34. updateText);
  35. goog.events.listen(focusHandler, goog.events.FocusHandler.EventType.FOCUSOUT,
  36. updateText);
  37. goog.events.listen(window, 'unload', function() {
  38. goog.events.unlisten(focusHandler, goog.events.FocusHandler.EventType.FOCUSIN,
  39. updateText);
  40. goog.events.unlisten(focusHandler,
  41. goog.events.FocusHandler.EventType.FOCUSOUT, updateText);
  42. });
  43. </script>
  44. </body>
  45. </html>