Guest User

Untitled

a guest
Jan 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <style>
  2. .highlight { background:yellow; }
  3. </style>
  4.  
  5. <script>
  6.  
  7. $(function() {
  8. $('td').click(function() {
  9. alert(event.target.id);
  10. $(this).toggleClass("highlight");
  11. });
  12. });
  13. </script>
  14. <%@ page import="java.util.*" %>
  15. <%
  16. ArrayList<String> rooms = new ArrayList<String>();
  17. rooms.add("GSR_2-1");
  18. rooms.add("GSR_2-2");
  19. rooms.add("GSR_2-3");
  20. rooms.add("GSR_2-4");
  21. ArrayList<String> time = new ArrayList<String>();
  22. time.add("0800");
  23. time.add("0830");
  24. time.add("0900");
  25. time.add("0930");
  26. %>
  27. <table width="100%" border="1">
  28. <%
  29. for(int x = 0 ; x<time.size() ; x++){
  30. out.println("<tr>");
  31. for(int y = 0 ; y<rooms.size() ; y++){
  32. out.println("<td id="+rooms.get(y) +">");
  33. out.println(rooms.get(y)+" "+time.get(x));
  34. out.println("</td>");
  35. }
  36. out.println("</tr>");
  37. }
  38. %>
  39.  
  40. $('td').click(function() {
  41. var $td = $(this);
  42. $td.closest('table').find('tr').each(function() {
  43. $(this).find('td:eq('+$td.index()+')').toggleClass("highlight");
  44. });
  45. });
  46.  
  47. <html>
  48.  
  49. <head>
  50.  
  51. <title>Classes</title>
  52.  
  53. </head>
  54.  
  55. <body>
  56.  
  57. <table>
  58.  
  59. <tr>
  60.  
  61. <td class='col1'>11</td>
  62. <td class='col2'>12</td>
  63.  
  64. </tr>
  65. <tr>
  66.  
  67. <td class='col1'>21</td>
  68. <td class='col2'>22</td>
  69.  
  70. </tr>
  71.  
  72. </table>
  73.  
  74. </body>
  75.  
  76. </html>
  77.  
  78. .highlight {
  79.  
  80. /* your style here*/
  81. background: #00aa00; /* demo highlight*/
  82.  
  83. }
  84. td {
  85.  
  86. padding: 2px;
  87.  
  88. }
  89.  
  90. $("table tr td").on("click", function(){
  91.  
  92. var clss = $(this).attr('class');
  93. var selector = "table tr td." + clss;
  94. if (clss.match(/highlight/)) {
  95. $(".highlight").removeClass("highlight");
  96. } else if ($(".highlight").size() == 0) {
  97. $(selector).addClass("highlight");
  98. }
  99. });​
Add Comment
Please, Sign In to add comment