element_change_detector.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ADvanced Form</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
  6. <script src="js/jquery-1.6.2-min.js"></script>
  7. </head>
  8. <body>
  9. <h1>ADvanced Form Page</h1>
  10. <form method="POST" enctype="multipart/form-data" action="advanced_form_post.php">
  11. <input id="the-input-default" value="" />
  12. <input type="text" id="the-input-text" value="" />
  13. <input type="email" id="the-email" value="" />
  14. <select id="the-select">
  15. <option value="10">ten</option>
  16. <option value="20" selected="selected">twenty</option>
  17. <option value="30">thirty</option>
  18. </select>
  19. <label>
  20. <span><input type="radio" name="sex" id="the-radio-m" value="m" /> m</span>
  21. <span><input type="radio" name="sex" id="the-radio-w" value="w" checked="checked" /> w</span>
  22. </label>
  23. <input type="checkbox" id="the-checked-checkbox" value="cb-val" checked/>
  24. <input type="checkbox" id="the-unchecked-checkbox" value="cb-val"/>
  25. <textarea id="the-textarea"></textarea>
  26. <input type="file" id="the-file" />
  27. </form>
  28. <ul id="results" style="border: 1px solid red;">
  29. <li>for easy element location</li>
  30. </ul>
  31. <script type="text/javascript">
  32. $(document).ready(function () {
  33. var $change_registry = {},
  34. $results = $('#results');
  35. $(':input').change(function () {
  36. var $result_id = this.id + '-result';
  37. if (!$change_registry[this.id]) {
  38. $change_registry[this.id] = 1;
  39. $results.append('<li id="' + $result_id + '"></li>');
  40. }
  41. else {
  42. $change_registry[this.id]++;
  43. }
  44. $('#' + $result_id).text($change_registry[this.id]);
  45. });
  46. $results.click(function () {
  47. $results.empty();
  48. $change_registry = {};
  49. });
  50. });
  51. </script>
  52. </body>
  53. </html>