asimryu

jquery xml dialog(2015.06.18)

Jun 17th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.18 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="ko">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>jQuery XML</title>
  6. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css">
  7. <script src="http://code.jquery.com/jquery-latest.js"></script>
  8. <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. </head>
  10. <body>
  11. <table>
  12.     <tbody>
  13.         <tr>
  14.             <td>번호</td>
  15.             <td>과정</td>
  16.             <td>이름</td>
  17.             <td>소속</td>
  18.             <td>학년</td>
  19.         </tr>
  20.     </tbody>
  21. </table>
  22. <div id="dialog" title="학생정보">
  23.     <p>과정 : <span id="classtitle"></span></p>
  24.     <p>소속 : <span id="school"></span></p>
  25.     <p>이름 : <span id="sname"></span></p>
  26.     <p>학년 : <span id="year"></span></p>
  27. </div>
  28. <script>
  29.     $.ajax({
  30.         type: "GET",
  31.         url: "list.xml",
  32.         dataType: "XML",
  33.         success: function(xml){
  34.             $list = $(xml).find("student");
  35.             var sno = 0;
  36.             $list.each(function(){
  37.                 sno++;
  38.                 var classtitle = $(this).find("classtitle").text();
  39.                 var sname = $(this).find("sname").text();
  40.                 var school = $(this).find("school").text();
  41.                 var year = $(this).find("year").text();
  42.                 var tr = "<tr>";
  43.                 tr += "<td>" + sno + "</td>";
  44.                 tr += "<td>" + classtitle + "</td>";
  45.                 tr += "<td>" + sname + "</td>";
  46.                 tr += "<td>" + school + "</td>";
  47.                 tr += "<td>" + year + "</td>";
  48.                 tr += "</tr>";
  49.                 $("table > tbody").append( tr );
  50.             });
  51.         }
  52.     });
  53.     $("tr:first > td").css("background-color","gray");
  54.     $(document).on("mouseover","tr:not(:first-child) > td",
  55.         function(){
  56.             $(this).parent("tr").children("td").css("background-color","yellow");
  57.         }
  58.     );
  59.     $(document).on("mouseout","tr:not(:first-child) > td",
  60.         function(){
  61.             $(this).parent("tr").children("td").css("background-color","white");
  62.         }
  63.     );
  64.     $("#dialog").hide();
  65.     $(document).on("click","tr:not(:first-child) > td",             function(){
  66.         var data = $(this).parent("tr").children("td");
  67.         var classtitle = $(data[1]).html();
  68.         var sname = $(data[2]).html();
  69.         var school = $(data[3]).html();
  70.         var year = $(data[4]).html();
  71.         $("#classtitle").html(classtitle);
  72.         $("#sname").html(sname);
  73.         $("#school").html(school);
  74.         $("#year").html(year);
  75.         $("#dialog").dialog();
  76.     });
  77.  
  78. </script>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment