08 June 2016

Tạo menu tab, danh sách động trên html web tĩnh bằng Javascript rất hay dùng trên các web phim

Hình Ảnh Demo



 css
 Web 2016
#sel1{
    cursor:pointer;
    background-color:rgb(200,200,200);
    padding-left:13px;
    padding-right:13px;
}
#sel2{
    cursor:pointer;
    background-color:rgb(150,150,150);
    padding-left:13px;
    padding-right:13px;
}
#sel3{
    cursor:pointer;
    background-color:rgb(150,150,150);
    padding-left:13px;
    padding-right:13px;
}
#resultsel1{
    display:block;
    position:relative;
    bottom:1px;
    width:100%;
    height:30px;
    background-color:rgb(200,200,200);
}
#resultsel2{
    display:none;
    position:relative;
    bottom:1px;
    width:100%;
    height:30px;
    background-color:rgb(200,200,200);
}
#resultsel3{
    display:none;
    position:relative;
    bottom:1px;
    width:100%;
    height:30px;
    background-color:rgb(200,200,200);
}
Javascript and html
Web 2016
<SCRIPT>
    var selected="sel1";
    var disp="resultsel1";
    function show(a,b)
    {
      document.getElementById(selected).style.backgroundColor = "rgb(150,150,150)";
      document.getElementById(disp).style.display = "none";
    
      document.getElementById(a).style.backgroundColor = "rgb(200,200,200)";      
      
      document.getElementById(b).style.display = "block";
    selected=a;
    disp=b;
    }
</SCRIPT>
<div width="100%">
    <span id='sel1' onclick="show('sel1','resultsel1');">home</span><span id='sel2' onclick="show('sel2','resultsel2');">div1</span><span id='sel3' onclick="show('sel3','resultsel3');">div2</span></div>
<div id="resultsel1">Home Page</div>
<div id="resultsel2">div2</div>
<div id="resultsel3">div3</div>

Ví dụ thực tế:




Related Posts:

  • Sự khác nhau giữa function declaration và expression trong JavascriptTrong JavaScript, có hai cách khai báo hàm là function declaration (khai báo hàm) và function expression (biểu thức hàm). Dưới đây là sự khác nhau giữa hai cách này:  1. Function Declaration (Khai báo hàm): &nb… Read More
  • JS runtime cách xử lý bất đồng bộ và đồng bộ JS runtime (thời gian chạy của JavaScript) xử lý bất đồng bộ (asynchronous) và đồng bộ (synchronous) theo cách khác nhau.Khi JavaScript chạy trên trình duyệt, runtime sử dụng mô hình sự kiện (event-driven) để xử lý các … Read More
  • Non-blocking và BlockingNon-blocking và blocking là hai khái niệm quan trọng trong lập trình hướng đồng bộ.Non-blocking là một thuật ngữ được sử dụng để chỉ việc thực hiện một tác vụ mà không cần chờ đợi kết quả từ tác vụ đó. Trong một non-blocking … Read More
  • Có bao nhiêu Scopes trong JavascriptScope Levels1 - Global Scope2 - Module Scope3 - Block Scope4 - Function ScopeGlobal Scope<script src="script.js"></script><script>  // script.js  const a = 1  console.log(a)  // Prints: 1… Read More
  • Session và Cookie ?Session và Cookie là hai khái niệm quan trọng trong lập trình web để lưu trữ thông tin và duy trì trạng thái của người dùng trên trang web.  Session (Phiên làm việc) là một cơ chế lưu trữ thông tin trên máy chủ. Khi… Read More

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang