网站地图    收藏   

主页 > 前端 > css教程 >

PhoneGap-----DataBase - html/css语言栏目:html.css - 自学

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] EveryThing in the code!!![html]!DOCTYPE htmlhtmlheadtitleDataBase Example/titlescript type=text/javascript charset=utf-8 src=cordova.js/scriptscript type=text/javasc......

EveryThing in the code!!!


[html]
<!DOCTYPE html> 
<html> 
<head> 
<title>DataBase Example</title> 
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> 
<script type="text/javascript" charset="utf-8"> 
   document.addEventListener("deviceready",onDeviceReady,false); 
    
   function populateDB(tx){ 
       tx.executeSql('DROP TABLE IF EXISTS test1'); 
       tx.executeSql('CREATE TABLE IF NOT EXISTS test1(id unique,name)'); 
       tx.executeSql('INSERT INTO test1(id,name)VALUES(1,"Tony")'); 
       tx.executeSql('INSERT INTO test1(id,name)VALUES(2,"Bill")'); 
       tx.executeSql('INSERT INTO test1(id,name)VALUES(3,"Thomas")'); 
   } 
    
   function queryDB(tx){ 
       tx.executeSql('SELECT * FROM test1',[],querySuccess,errorDB); 
   } 
    
   function querySuccess(tx,results){ 
       var len = results.rows.length; 
       var status = document.getElementById("status"); 
       var string = "Rows: " + len + "<br/>"; 
       for(var i = 0;i<len;i++){ 
           string += results.rows.item(i).name + "<br/>"; 
       } 
       status.innerHTML = string; 
   } 
    
   function errorDB(err){ 
       alert("Error processing SQL: "+err.code); 
   } 
    
   function successDB(){ 
       var db = window.openDatabase("Test","1.0","Test",200000); 
       db.transaction(queryDB,errorDB); 
   } 
    
   function onDeviceReady(){ 
       var db = window.openDatabase("Test","1.0","Test",200000); 
       db.transaction(populateDB,errorDB,successDB); 
   } 
    
</script> 
</head> 
<body> 
   <h1>Names</h1> 
   <div id="status"></div> 
</body> 
</html> 

<!DOCTYPE html>
<html>
<head>
<title>DataBase Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
   document.addEventListener("deviceready",onDeviceReady,false);
  
   function populateDB(tx){
    tx.executeSql('DROP TABLE IF EXISTS test1');
    tx.executeSql('CREATE TABLE IF NOT EXISTS test1(id unique,name)');
    tx.executeSql('INSERT INTO test1(id,name)VALUES(1,"Tony")');
    tx.executeSql('INSERT INTO test1(id,name)VALUES(2,"Bill")');
    tx.executeSql('INSERT INTO test1(id,name)VALUES(3,"Thomas")');
   }
  
   function queryDB(tx){
    tx.executeSql('SELECT * FROM test1',[],querySuccess,errorDB);
   }
  
   function querySuccess(tx,results){
    var len = results.rows.length;
    var status = document.getElementById("status");
    var string = "Rows: " + len + "<br/>";
    for(var i = 0;i<len;i++){
     string += results.rows.item(i).name + "<br/>";
    }
    status.innerHTML = string;
   }
  
   function errorDB(err){
    alert("Error processing SQL: "+err.code);
   }
  
   function successDB(){
    var db = window.openDatabase("Test","1.0","Test",200000);
    db.transaction(queryDB,errorDB);
   }
  
   function onDeviceReady(){
    var db = window.openDatabase("Test","1.0","Test",200000);
    db.transaction(populateDB,errorDB,successDB);
   }
  
</script>
</head>
<body>
   <h1>Names</h1>
   <div id="status"></div>
</body>
</html>

 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论