[Simple message book] is implemented using the newly added HTML database, and the message book is added
Database-implemented WEB message book
Var datatable = null;
Var db = openDatabase ('mydata', '', 'My database', 102400 );
Function init (){
Datatable = document. getElementById ("datatable ");
ShowAllData ();
}
Function removeAllData (){
For (var I = datatable. childNodes. length-1; I> = 0; I --){
Datatable. removeChild (datatable. childNodes [I]);
}
Var tr = document. createElement ('tr ');
Var th1 = document. createElement ('th ');
Var 2nd = document. createElement ('th ');
Var th3 = document. createElement ('th ');
Th1.innerHTML = "name ";
Th2.innerHTML = "message ";
Th3.innerHTML = "time ";
Tr. appendChild (th1 );
Tr. appendChild (2nd );
Tr. appendChild (th3 );
Datatable. appendChild (tr );
}
Function showData (row ){
Var tr = document. createElement ('tr ');
Var td1 = document. createElement ('td ');
Td1.innerHTML = row. name;
Var td2 = document. createElement ('td ');
Td2.innerHTML = row. message;
Var td3 = document. createElement ('td ');
Var t = new Date ();
T. setTime (row. time );
Td3.innerHTML = t. toLocaleDateString () + "" + t. toLocaleTimeString ();
Tr. appendChild (td1 );
Tr. appendChild (td2 );
Tr. appendChild (td3 );
Datatable. appendChild (tr );
}
Function showAllData (){
Db. transaction (function (tx ){
Tx.exe cuteSql ('create table if not exists MsgData (name TEXT, message TEXT, time INTEGER) ', []);
Tx.exe cuteSql ('select * FROM msgdata', [], function (tx, rs ){
RemoveAllData ();
For (var I = 0; I <rs. rows. length; I ++ ){
ShowData (rs. rows. item (I ));
}
});
});
}
Function addData (name, message, time ){
Db. transaction (function (tx ){
Tx.exe cuteSql ('insert INTO MsgData VALUES (?,?,?) ', [Name, message, time], function (tx, rs ){
Alert ("data is saved successfully! ");
}, Function (tx, rs ){
Alert (error. source + ":" + error. message );
});
});
}
Function saveData (){
Var name = document. getElementById ('name'). value;
Var memo = document. getElementById ('memo'). value;
Var time = new Date (). getTime ();
// Alert (time );
AddData (name, memo, time );
ShowAllData ();
}
Database-implemented Web message book