您好,欢迎来到12图资源库!分享精神,快乐你我!我们只是素材的搬运工!!
  • 首 页
  • 当前位置:首页 > 网站教程 > HTML教程 >
    基于HTML5构建Web操作系统(5)
    时间:2016-07-13 21:12 来源: 作者: 浏览:收藏 挑错 推荐 打印
  •  
  •  
  •  function addHistory(time, action, details){   
  •  if(openDatabase != undefined)   
  •  db.transaction(   
  •  function(tx) {   
  •  tx.executeSql('CREATE TABLE IF NOT EXISTS History(time INTEGER,   
  •  action TEXT, details TEXT)',[]);// 创建日志记录表    
  •  tx.executeSql('INSERT INTO History VALUES(?, ?, ?)', [time,   
  •  action, details], // 插入一条日志  
  •  function(tx, rs) {    
  •  //alert("store: "+time+"-"+action+"-"+details);     
  •               },    
  •  function(tx, error) {   
  •     //alert(error.source + "::" + error.message);    
  •  });    
  •  });    
  •  }  
  • 清单的第一部分显示了如何调用日志记录,第二部分显示了日志记录的详细过程。在一个transaction中,首先判断表History是否存在,若不存在,则创建它。第二部分执行一条SQL语句,向数据库中插入当前的日志。
    通过检索表History,我们可以查看系统日志,清单12显示了如何从数据库中查询系统日志,并将其显示出来。
    清单 12.日志显示
    1. var historyTable = document.getElementById("historyTable");   
    2.  
    3.  // 定义表头  
    4.  historyTable.innerHTML = "";   
    5.  var th = document.createElement('thead');   
    6.  th.style = "color:#CC3300";   
    7.  var th1 = document.createElement('td');   
    8.  th1.align = "center";   
    9.  th1.width=300;   
    10.  th1.innerHTML = "Time";   
    11.  var th2 = document.createElement('td');   
    12.  th2.align = "center";   
    13.  th2.width=100;   
    14.  th2.innerHTML = "Action";   
    15.  var th3 = document.createElement('td');   
    16.  th3.align = "center";   
    17.  th3.width=150;   
    18.  th3.innerHTML = "Details";   
    19.  th.appendChild(th1);    
    20.  th.appendChild(th2);    
    21.  th.appendChild(th3);   
    22.  historyTable.appendChild(th);   
    23.                  
    24.  if(openDatabase != undefined)   
    25.  db.transaction(function(tx) {      
    26.  tx.executeSql('SELECT * FROM History', [], function(tx, rs)   
    27.  {    
    28.       // 将日志逐条显示到表的各行中  
    29.  for(var i = 0; i < rs.rows.length && i<15; i++) {                      
    30.  var tr = document.createElement('tr');   
    31.  var td1 = document.createElement('td');   
    32.  td1.style.paddingLeft = "3px";   
    33.  td1.style.paddingRight = "3px";   
    34.                       
    35.  var t = new Date();    
    36.  t.setTime(rs.rows.item(i).time);    
    37.  ttd1.innerHTML = t.toLocaleDateString()+   
    38. " "+t.toLocaleTimeString();   
    39.    

      (责任编辑:12图资源库)