【簡單的留言本】用HTML新增的數(shù)據(jù)庫實現(xiàn)
資興ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!
使用數(shù)據(jù)庫實現(xiàn)的WEB留言本
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 th2 = document.createElement('th');
var th3 = document.createElement('th');
var th4 = document.createElement('th');
th2.innerHTML = "姓名";
th3.innerHTML = "留言";
th4.innerHTML = "時間";
tr.appendChild(th2);
tr.appendChild(th3);
tr.appendChild(th4);
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.executeSql('CREATE TABLE IF NOT EXISTS MsgData(name TEXT,message TEXT,time INTEGER)',[]);
tx.executeSql('SELECT * FROM MsgData',[],function (tx,rs) {
removeAllData();
for(var i =0 ;i showData(rs.rows.item(i)); } }); }); } function addData(name,message,time) { db.transaction(function (tx) { tx.executeSql('INSERT INTO MsgData VALUES(?,?,?)',[name,message,time],function (tx,rs) { alert("成功保存數(shù)據(jù)!"); },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(); } 使用數(shù)據(jù)庫實現(xiàn)的Web留言本 姓名: 留言: ________________________________________
文章名稱:【簡單的留言本】用HTML新增的數(shù)據(jù)庫實現(xiàn)
標(biāo)題URL:http://weahome.cn/article/gojepd.html