Created
February 3, 2018 07:27
-
-
Save crongro/291c5555b63a0afa41960e09d0173e06 to your computer and use it in GitHub Desktop.
tabui_base_code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <header> | |
| <link rel="stylesheet" href="tabui.css"> | |
| <style> | |
| h2 { | |
| text-align: center | |
| } | |
| h2, | |
| h4 { | |
| margin: 0px; | |
| } | |
| .tab { | |
| width: 600px; | |
| margin: 0px auto; | |
| } | |
| .tabmenu { | |
| background-color: bisque; | |
| } | |
| .tabmenu>div { | |
| display: inline-block; | |
| width: 146px; | |
| height: 50px; | |
| line-height: 50px; | |
| text-align: center; | |
| cursor: pointer; | |
| } | |
| .content { | |
| padding: 5%; | |
| background-color: antiquewhite; | |
| } | |
| </style> | |
| </header> | |
| <body> | |
| <h2> TAB UI TEST</h2> | |
| <div class="tab"> | |
| <div class="tabmenu"> | |
| <div>crong</div> | |
| <div>jk</div> | |
| <div>pobi</div> | |
| <div>honux</div> | |
| </div> | |
| <section class="content"> | |
| <h4>hello jk</h4> | |
| <p>golf, facebook</p> | |
| </section> | |
| </div> | |
| <script> | |
| function makeTemplate(data, clickedName) { | |
| var html = document.getElementById("tabcontent").innerHTML; | |
| var resultHTML = ""; | |
| for (var i = 0; i < data.length; i++) { | |
| if (data[i].name === clickedName) { | |
| resultHTML = html.replace("{name}", data[i].name) | |
| .replace("{favorites}", data[i].favorites.join(" ")); | |
| break; | |
| } | |
| } | |
| document.querySelector(".content").innerHTML = resultHTML; | |
| } | |
| function sendAjax(url, clickedName) { | |
| var oReq = new XMLHttpRequest(); | |
| oReq.addEventListener("load", function () { | |
| var data = JSON.parse(oReq.responseText); | |
| makeTemplate(data, clickedName); | |
| }); | |
| oReq.open("GET", url); | |
| oReq.send(); | |
| } | |
| var tabmenu = document.querySelector(".tabmenu"); | |
| tabmenu.addEventListener("click", function (evt) { | |
| sendAjax("./json.txt", evt.target.innerText); | |
| }); | |
| </script> | |
| <script id="tabcontent" type="my-template"> | |
| <h4>hello {name}</h4> | |
| <p>{favorites}</p> | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment