[Simple message book] is implemented using the newly added HTML database, and the message book is added

Source: Internet
Author: User

[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

 

 

Name:

 

 

Message:

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.