• Thế Giới Giải Mã

    Bí ẩn nhân loại Leonardo Da Vinci

  • Thế Giới Giải Mã

    Anh hùng thầm lặng Nikola Tesla

  • Thế Giới Giải Mã

    Thần đèn Thomas Edison

  • Thế Giới Giải Mã

    Người thôi miên Adolf Hitler

Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts

14 July 2017

Html: Tạo Scroll y trên Table và Tự động điều chỉnh độ rộng width của thẻ th bằng với độ rộng của thẻ td nội dung bên dưới bằng Javascript


Tự động điều chỉnh độ rộng của thẻ th dựa vào dòng nội dung dài nhất trong column đó
Scroll y Table điều chỉnh th bằng Javascript
Html 2017
<!DOCTYPE html>
<html>
<head>
<style>
table.scroll {
    border-spacing: 0;
    border: 2px solid black;
}

table.scroll tbody,
table.scroll thead { display: block; }

thead tr th { 
    height: 30px;
    line-height: 30px;
}

table.scroll tbody {
    height: 100px;
    overflow-y: auto;
    overflow-x: hidden;
}

tbody { border-top: 2px solid black; }

tbody td, thead th {
    border-right: 1px solid black;
    /* white-space: nowrap; */ Tự động dàn văn bản k xuống dòng
}

tbody td:last-child, thead th:last-child {
    border-right: none;
}
</style>

</head>
<body>

  <table class="scroll">
    <thead>
        <tr>
            <th>Head 1</th>
            <th>Head 2</th>
            <th>Head 3</th>
            <th>Head 4</th>
            <th>Head 5</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Lorem ipsum</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Lorem ipsum dolor sit</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Lorem ipsum dolor sit amet</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
   <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
        <tr>
            <td>Content 1</td>
            <td>Content 2</td>
            <td>Content 3</td>
            <td>Content 4</td>
            <td>Content 5</td>
        </tr>
    </tbody>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var table = $('table.scroll'), bodyCells = table.find('tbody tr:first').children(),colWidth;

$(window).resize(function() {
    colWidth = bodyCells.map(function() {
        return $(this).width();
    }).get();
    
    table.find('thead tr').children().each(function(i, v) {
        //$(v).text() => Head 1 .. Head 2 .. etc
        //colWidth[i] => 150 ...
        //i => 1 ~ 5 
        //$(this).css("min-width", colWidth[i]);
        $(v).width(colWidth[i]);
    });    
}).resize();
</script>
</body>
</html>
Nguồn: https://codedump.io/share/9ozwCMzEuc68/1/html-table-with-100-width-with-vertical-scroll-inside-tbody
Run demo 'lưu ý phải kéo đường kẻ ngăn của tool'

13 July 2017

Html: Tạo Scroll xy trên Table - Fixed table header with x/y scrolling

Tạo Scroll xy trên Table
Html 2017
<!DOCTYPE html>
<html>
<head>

<style>
html {
    font-family: verdana;
    font-size: 10pt;
    line-height: 25px;
}
table {
    border-collapse: collapse;
    width: 1035px;
    overflow-x: scroll;
    display: block;
}
thead {
    background-color: rgba(141, 159, 189, 0.34);
}
thead, tbody {
    display: block;
}
tbody {
    overflow-y: scroll;
    overflow-x: hidden;
    height: 525px;
}
td, th {
    min-width: 100px;
    height: 25px;
    border: solid 1px rgba(141, 159, 189, 0.34);
}
td:nth-child(6),th:nth-child(6){
    min-width: 230px;
}
td:nth-child(5),th:nth-child(5){
    min-width: 150px;
}
td:nth-child(3),th:nth-child(3){
    min-width: 220px;
}
td:nth-child(2),th:nth-child(2){
    min-width: 270px;
}
td:nth-child(1),th:nth-child(1){
    min-width: 170px;
}
</style>

</head>
<body>

  <table>
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
            <th>Column 4</th>
            <th>Column 5</th>
     <th>Column 6</th>
        </tr>
    </thead>
    <tbody>
  <tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr>
       <tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr><tr>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
            <td>Row 1</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
            <td>Row 2</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
            <td>Row 3</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
            <td>Row 4</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
            <td>Row 5</td>
     <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
            <td>Row 6</td>
     <td>Row 1</td>
        </tr>
    </tbody>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/index.js"></script>
</body>
</html>
index.js
$('table').on('scroll', function() {
  $("table > *").width($("table").width() + $("table").scrollLeft());
});
Run demo
$("tbody").hover(
  function() {
    $(this).css("overflow-y", "scroll");
  },
  function() {
    $(this).css("overflow-y", "hidden");
  }
);
Run demo

12 July 2017

Html: Tạo độ rộng cho từng cột trong Table với thẻ colgroup

Tạo độ rộng cho từng cột trong Table
Html 2017
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}
</style>
</head>
<body>

<table>
  <colgroup>
    <col width="80" span="2">
    <col width="150" span="1">
    <col width=auto span="2">
    <col width="200" span="1">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
    
  </tr>
  <tr>
    <td>80px</td>
    <td>80xp</td>
    <td>150px</td>
    <td>Auto</td>
    <td>Auto</td>
    <td>200px</td>
  </tr>
</table>

</body>
</html>
Output:
ISBNTitlePriceISBNTitlePrice
80px80xp120pxAutoAuto200px

Test: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_colgroup_test
Run demo

16 April 2017

Html: Mẫu Table View Bootstrap JavaScript Jquery Data Json

index.html
Html 2017
<!DOCTYPE html>

<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/jquery.min.js"></script> 
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/trirand/i18n/grid.locale-en.js"></script>
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/trirand/jquery.jqGrid.min.js"></script>
    <!-- This is the localization file of the grid controlling messages, labels, etc.
    <!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    <!-- The link to the CSS that the grid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="http://www.guriddo.net/demo/css/trirand/ui.jqgrid-bootstrap.css" />
 <script>
  $.jgrid.defaults.width = 780;
 </script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - Million Rows from a REST service</title>
</head>
<body>
<div style="margin-left:20px">
    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>
</div>
    <script type="text/javascript"> 
        $(document).ready(function () {
   
            $("#jqGrid").jqGrid({
                url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/getjsonp.php?callback=?&qwery=longorders',
                mtype: "GET",
  styleUI : 'Bootstrap',
                datatype: "jsonp",
                colModel: [
                    { label: 'OrderID', name: 'OrderID', key: true, width: 75 },
                    { label: 'Customer ID', name: 'CustomerID', width: 150 },
                    { label: 'Order Date', name: 'OrderDate', width: 150 },
                    { label: 'Freight', name: 'Freight', width: 150 },
                    { label:'Ship Name', name: 'ShipName', width: 150 }
                ],
  viewrecords: true,
                height: 250,
                rowNum: 10,
                pager: "#jqGridPager"
            });
        });
 
   </script>
   
</body>
</html>

Html: Menu đa cấp đơn giản nhất

menu1.html
Html 2017
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
#menu {}
#menu ul {
 margin: 0px;
 padding: 0px;
 list-style-type: none;
}
#menu>ul>li {
 float:left;
}

#menu>ul>li>a {
 display:block;
 width:120px;
 border-left:1px solid #063;
 
 line-height:40px;
 text-decoration:none;
 background-color:#09C;
 
 font-family:Tahoma, Geneva, sans-serif;
 color:#FF0;
 text-align:center;
}

#menu ul li>ul{
 display:none;
 position:absolute; 
}
#menu ul li>ul a{
 display:block;
 width:200px;
 border-bottom:1px dotted #063; 
 line-height:40px;
 text-decoration:none;
 background-color:#9F9;
 font-family:Tahoma, Geneva, sans-serif;
 color:#FF0;
}
#menu ul li>ul a:hover{ 
 background-color:#FF6; 
 color:#063;
}
#menu ul li:hover ul{
 display:block;
}
</style>
</head>
<body>
<div id="menu">
  <ul>
    <li><a href="#">Tin thế giới</a> </li>
    <li><a href="#">Tin trong nước</a>
      <ul>
        <li><a href="#">Chính trị xã hội</a></li>
        <li><a href="#">An ninh pháp luật</a></li>
        <li><a href="#">Phóng sự - Ký sự</a></li>
        <li><a href="#">Kinh tế xã hội  </a></li>
      </ul>
    </li>
 
    <li><a href="#">Tin nóng</a>
      <ul>
        <li><a href="#">Tình hình sự kiện</a></li>
        <li><a href="#">Trang bị quân đội</a></li>
        <li><a href="#">Điểm nóng chiến sự</a></li>
        <li><a href="#">Buôn bán vũ khí </a></li>
      </ul>
    </li>   
 <li><a href="#">Kinh tế</a>
      <ul>
        <li><a href="#">Chính sách</a></li>
        <li><a href="#">Tài chính - Ngân hàng</a></li>
        <li><a href="#">Bất động sản</a></li>
        <li><a href="#">Chứng khoán</a></li>
        <li><a href="#">Doanh nghiệp</a></li>
        <li><a href="#">Hàng hóa</a></li>
        <li><a href="#">Năng lượng</a></li>
        <li><a href="#">Dịch vụ</a></li>
        <li><a href="#">Thị trường</a></li>
        <li><a href="#">Đầu tư </a></li>
      </ul>
    </li> 
 <li><a href="#">Văn hóa</a>
      <ul>
        <li><a href="#">Hoa hậu</a></li>
        <li><a href="#">Nghệ sỹ</a></li>
        <li><a href="#">Âm nhạc</a></li>
        <li><a href="#">Thời trang</a></li>
        <li><a href="#">Điện ảnh</a></li>
        <li><a href="#">Mỹ thuật</a></li>
        <li><a href="#">Văn học</a></li>        
        </ul>
    </li> 
    <li><a href="#">Hồn việt</a>
      <ul>
        <li><a href="#">Cảnh quan Đất Việt </a></li>
        <li><a href="#">Làng nghề</a></li>
        <li><a href="#">Phong tục tập quán</a></li>
        <li><a href="#">Dấu ấn thời gian</a></li>
        <li><a href="#">Dư vị Việt Nam</a></li>
        <li><a href="#">Dấu ấn thời gian  </a></li>
      </ul>
    </li>
    </ul>
  </div>
  
</body>
</html>

menu2.html
Html 2017
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
#menu ul {
 list-style-type: none;
}
#menu>ul>li {
 position:relative;
 width: 200px;
}

#menu>ul>li>a {
 display:block;
 width:200px;
 border-bottom:1px solid #063;
 
 line-height:40px;
 text-decoration:none;
 background-color:#09C;
  
 font-family:Tahoma, Geneva, sans-serif;
 color:#FF0; 
}

#menu ul li>ul{
 display:none;
 position:absolute; 
 left:160px;
 top:0px;
}
#menu ul li>ul a{
 display:block;
 width:200px;
 border-bottom:1px dotted #063; 
 line-height:40px;
 text-decoration:none;
 background-color:#9F9;
 font-family:Tahoma, Geneva, sans-serif;
 color:#FF0;
}
#menu ul li>ul a:hover{ 
 background-color:#FF6; 
 color:#063;
}
#menu ul li:hover ul{
 display:block;
}
</style>
</head>
<body>
<div id="menu">
  <ul>
    <li><a href="#">Tin thế giới</a> </li>
    <li><a href="#">Tin trong nước</a>
      <ul>
        <li><a href="#">Chính trị xã hội</a></li>
        <li><a href="#">An ninh pháp luật</a></li>
        <li><a href="#">Phóng sự - Ký sự</a></li>
        <li><a href="#">Kinh tế xã hội  </a></li>
      </ul>
    </li>
 
    <li><a href="#">Tin nóng</a>
      <ul>
        <li><a href="#">Tình hình sự kiện</a></li>
        <li><a href="#">Trang bị quân đội</a></li>
        <li><a href="#">Điểm nóng chiến sự</a></li>
        <li><a href="#">Buôn bán vũ khí </a></li>
      </ul>
    </li>   
 <li><a href="#">Kinh tế</a>
      <ul>
        <li><a href="#">Dịch vụ</a></li>
        <li><a href="#">Thị trường</a></li>
        <li><a href="#">Đầu tư </a></li>
      </ul>
    </li> 
    </ul>
  </div>
 
</body>
</html>

23 March 2017

Validation JQuery vs Bootstrap3 ngắn gọn dễ hiểu

validate.js
JQuery 2017
$(document).ready(function () {
    $('#reg_form').bootstrapValidator({
        fields: {
            username: {
                message: 'The username is not valid',
                validators: {
                    notEmpty: {
                        message: 'The username is required and can\'t be empty'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The username must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: 'The username can only consist of alphabetical, number, dot and underscore'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: 'The password is required and can\'t be empty'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The password must be more than 6 and less than 30 characters long'
                    }
                }
            },
            confirmPassword: {
                validators: {
                    notEmpty: {
                        message: 'The confirm password is required and can\'t be empty'
                    },
                    identical: {
                        field: 'password',
                        message: 'The password and its confirm are not the same'
                    }
                }
            },
            ages: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your age'
                    },
                    lessThan: {
                        value: 100,
                        inclusive: true,
                        message: 'The ages has to be less than 100'
                    },
                    greaterThan: {
                        value: 10,
                        inclusive: false,
                        message: 'The ages has to be greater than or equals to 10'
                    }
                }
            },
            email: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your email address'
                    },
                    emailAddress: {
                        message: 'Please supply a valid email address'
                    }
                }
            },
            phone: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your phone number'
                    },
                    // phone: {
                    // //http://formvalidation.io/validators/phone/
                    // country: 'US',
                    // message: 'Please supply a
                    // vaild phone number with
                    // area code'
                    // },
                    regexp: {
                        // Test regex:
                        // https://regex101.com
                        regexp: /^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}$/,
                        message: 'Please supply a vaild phone number with area code'
                    }
                }
            },
            state: {
                validators: {
                    notEmpty: {
                        message: 'Please select your Option'
                    }
                }
            },
            zip: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your zip code'
                    },
                    zipCode: {
                        country: 'US',
                        message: 'Please supply a vaild zip code'
                    }
                }
            },
            money: {
                validators: {
                    integer: {
                        message: 'The value is not an integer'
                    },
                    between: {
                        // http://formvalidation.io/validators/numeric/
                        min: 1,
                        max: 1000000000,
                        message: 'The latitude must be between 1 and 1.000.000.000 VND'
                    },
                    notEmpty: {
                        message: 'Please supply money'
                    }
                }
            },
            birthday: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your birthday'
                    },
                    date: {
                        format: 'YYYY/MM/DD',
                        message: 'The birthday is not valid'
                    }
                }
            },
            website: {
                validators: {
                    notEmpty: {
                        message: 'Please supply URL'
                    },
                    uri: {
                        allowLocal: true,
                        message: 'The input is not a valid URL'
                    }
                }
            },
            comment: {
                validators: {
                    stringLength: {
                        min: 10,
                        max: 200,
                        message: 'Please enter at least 10 characters and no more than 200'
                    },
                    notEmpty: {
                        message: 'Please supply a description of your project'
                    }
                }
            }
        }
    })

            .on(
                    'success.form.bv',
                    function (e) {
                        $('#success_message').slideDown({
                            opacity: "show"
                        }, "slow") // Do something ...
                        $('#reg_form').data(
                                'bootstrapValidator')
                                .resetForm();

                        e.preventDefault();

                        var $form = $(e.target);

                        var bv = $form
                                .data('bootstrapValidator');

                        $.post($form.attr('action'), $form
                                .serialize(), function (result) {
                            console.log(result);
                        }, 'json');
                    });
});
index.html
JQuery 2017
<!doctype html>
<html>
    <head>
        <title>Validation JQuery</title>
    </head>
    <body>

        <div class="col-lg-9">

            <form id="reg_form" >

                <div class="form-group">
                    <!--class form-group này giúp thông báo hiển thị ở gần ngay tại input đó nhưng nó nằm bên phải-->
                    <div class="input-group">
                        <!--Thêm class input-group này bên trong để thống báo hiển thị nhảy xuống dòng ngay dưới input đó--> 
                        <input name="username" placeholder="Enter text Username" type="text">
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input name="password" type="password" placeholder="Enter text Password">
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input type="password" name="confirmPassword" placeholder="Confirm password">
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input type="text" name="ages" placeholder="Enter number Age">
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input name="email" placeholder="Enter text E-Mail Address" type="text">
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input name="phone" placeholder="###-###-####" data-format="+84(ddd)ddd-ddd" type="text">
                    </div>
                </div>

                <div class="form-group">

                    <div class="input-group">
                        <select name="state" class="selectpicker">
                            <option value=" ">Please select your option</option>
                            <option>Ha Noi</option>
                            <option>TP HCM</option>
                            <option>Vung Tau</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input name="zip" placeholder="Enter number Zip Code" type="text">
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input type="text" name="money"  placeholder="Enter number money" />
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input type="text" name="birthday" placeholder="(YYYY/MM/DD)" />
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <input type="text" name="website" placeholder="http://google.com.vn" />
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <textarea name="comment" placeholder="Enter textarea"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <input type="submit" class="btn btn-warning" value="Send"/>
                </div>
            </form>
        </div>

        <!--Cần đến sự có mặt của jquery.min và bootstrapvalidator--> 
        <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
        <script src='http://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js'></script>
        <!--Còn validate.js để chúng ta trực tiếp điều khiển logic validate lên đó-->
        <script src="js/validate.js"></script>

    </body>
</html>

03 December 2016

Validator Bootstrap 3 - Bắt lỗi form bằng Javascrip Bootstrap 3

index.html
Validator Html 2016
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Validation Bootstrap 3</title>
        <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
        <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>
        <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css'>
        <link rel='stylesheet prefetch' href='http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.0/css/bootstrapValidator.min.css'>
        <link rel="stylesheet" href="css/style_validate_bootstrap_3.css">
    </head>
    <body>
        <div class="container">

            <form class="well form-horizontal" action=" " method="post"  id="contact_form">
                <fieldset>

                    <!-- Form Name -->
                    <center><legend>Validation Bootstrap 3</legend></center>

                    <!-- Text input username-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">User Name</label>  
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                <input name="username" placeholder="Enter text Username" class="form-control"  type="text">
                            </div>
                        </div>
                    </div>

                    <!-- Text input password-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Password</label>
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                <input name="password" type="password" class="form-control" placeholder="Enter text Password" >
                            </div>
                        </div>
                    </div>

                    <!-- Text input confirm password-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Confirm Password</label>
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                <input type="password" name="confirmPassword" class="form-control" placeholder="Confirm password" >
                            </div>
                        </div>
                    </div>

                    <!-- Text input age-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Age</label>
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-heart"></i></span>
                                <input type="text" name="ages" class="form-control" placeholder="Enter number Age" >
                            </div>
                        </div>
                    </div>

                    <!-- Text input Email-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">E-Mail</label>  
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
                                <input name="email" placeholder="Enter text E-Mail Address" class="form-control"  type="text">
                            </div>
                        </div>
                    </div>

                    <!-- Text input number phone-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Phone #</label>  
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
                                <input name="phone" placeholder="###-###-####" data-format="+84(ddd)ddd-ddd" class="form-control" type="text" >
                            </div>
                        </div>
                    </div>

                    <!-- Select option basic -->
                    <div class="form-group"> 
                        <label class="col-md-4 control-label">Option</label>
                        <div class="col-md-4 selectContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
                                <select name="state" class="form-control selectpicker" >
                                    <option value=" " >Please select your option</option>
                                    <option>Ha Noi</option>
                                    <option>TP HCM</option>
                                    <option >Vung Tau</option>
                                    <option >Da Nang</option>
                                    <option >Hue</option>
                                    <option >Hai Phong</option>
                                    <option >Cam Ranh</option>
                                    <option >Nha Trang</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <!-- Text input Zip Code-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Zip Code</label>  
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-tasks"></i></span>
                                <input name="zip" placeholder="Enter number Zip Code" class="form-control"  type="text">
                            </div>
                        </div>
                    </div>

                    <!-- Text input Number -->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Money</label>
                        <div class="col-md-4 inputGroupContainer" >
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
                                <input type="text" class="form-control" name="money" placeholder="Enter number money"/>
                            </div>
                        </div>
                    </div>

                    <!-- Number input Date-->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Birthday</label>
                        <div class="col-md-4 inputGroupContainer" >
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
                                <input type="text" class="form-control" name="birthday" placeholder="(YYYY/MM/DD)" /> 
                            </div>
                        </div>
                    </div>

                    <!-- Text input http -->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Website</label>
                        <div class="col-md-4 inputGroupContainer" >
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-link"></i></span>
                                <input type="text" class="form-control" name="website" placeholder="http://google.com.vn" />
                            </div>
                        </div>
                    </div>

                    <!-- Text area -->
                    <div class="form-group">
                        <label class="col-md-4 control-label">Comment</label>
                        <div class="col-md-4 inputGroupContainer">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
                                <textarea class="form-control" name="comment" placeholder="Enter textarea"></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- Success message -->
                    <div class="alert alert-success" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> Thanks for contacting us, we will get back to you shortly.</div>

                    <!-- Button -->
                    <div class="form-group">
                        <label class="col-md-4 control-label"></label>
                        <div class="col-md-4">
                            <button type="submit" class="btn btn-warning" >Send <span class="glyphicon glyphicon-send"></span></button>
                        </div>
                    </div>

                </fieldset>
            </form>

        </div>
    </div><!-- /.container -->
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'></script>
    <script src='http://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js'></script>
    <script src="js/validate_bootstrap_3.js"></script>
</body>
</html>
validate_bootstrap_3.js
Validator Html 2016
$(document).ready(function () {
    $('#contact_form').bootstrapValidator({
        
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                message: 'The username is not valid',
                validators: {
                    notEmpty: {
                        message: 'The username is required and can\'t be empty'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The username must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: 'The username can only consist of alphabetical, number, dot and underscore'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: 'The password is required and can\'t be empty'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The password must be more than 6 and less than 30 characters long'
                    }
                }
            },
            confirmPassword: {
                validators: {
                    notEmpty: {
                        message: 'The confirm password is required and can\'t be empty'
                    },
                    identical: {
                        field: 'password',
                        message: 'The password and its confirm are not the same'
                    }
                }
            },
            ages: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your age'
                    },
                    lessThan: {
                        value: 100,
                        inclusive: true,
                        message: 'The ages has to be less than 100'
                    },
                    greaterThan: {
                        value: 10,
                        inclusive: false,
                        message: 'The ages has to be greater than or equals to 10'
                    }
                }
            },
            email: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your email address'
                    },
                    emailAddress: {
                        message: 'Please supply a valid email address'
                    }
                }
            },
            phone: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your phone number'
                    },
//                    phone: {
//                        //http://formvalidation.io/validators/phone/
//                        country: 'US',
//                        message: 'Please supply a vaild phone number with area code'
//                    },
                    regexp: {
                        //Test regex: https://regex101.com
                        regexp: /^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}$/,
                        message: 'Please supply a vaild phone number with area code'
                    }
                }
            },
            state: {
                validators: {
                    notEmpty: {
                        message: 'Please select your Option'
                    }
                }
            },
            zip: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your zip code'
                    },
                    zipCode: {
                        country: 'US',
                        message: 'Please supply a vaild zip code'
                    }
                }
            },
            money: {
                validators: {
                    integer: {
                        message: 'The value is not an integer'
                    },
                    between: {
                        //http://formvalidation.io/validators/numeric/
                        min: 1,
                        max: 1000000000,
                        message: 'The latitude must be between 1 and 1.000.000.000 VND'
                    },
                    notEmpty: {
                        message: 'Please supply money'
                    }
                }
            },
            birthday: {
                validators: {
                    notEmpty: {
                        message: 'Please supply your birthday'
                    },
                    date: {
                        format: 'YYYY/MM/DD',
                        message: 'The birthday is not valid'
                    }
                }
            },
            website: {
                validators: {
                    notEmpty: {
                        message: 'Please supply URL'
                    },
                    uri: {
                        allowLocal: true,
                        message: 'The input is not a valid URL'
                    }
                }
            },
            comment: {
                validators: {
                    stringLength: {
                        min: 10,
                        max: 200,
                        message: 'Please enter at least 10 characters and no more than 200'
                    },
                    notEmpty: {
                        message: 'Please supply a description of your project'
                    }
                }
            }}
    })
            .on('success.form.bv', function (e) {
                $('#success_message').slideDown({opacity: "show"}, "slow") // Do something ...
                $('#contact_form').data('bootstrapValidator').resetForm();

                // Prevent form submission
                e.preventDefault();

                // Get the form instance
                var $form = $(e.target);

                // Get the BootstrapValidator instance
                var bv = $form.data('bootstrapValidator');

                // Use Ajax to submit form data
                $.post($form.attr('action'), $form.serialize(), function (result) {
                    console.log(result);
                }, 'json');
            });
});
Validate Radio and CheckBox Bootstrap 3
Download zip | Xem thêm (examples)

 

BACK TO TOP

Xuống cuối trang