a页面上的数据通过url传递到b页面后,如何存储到html5的本地存储中?要把html5:txtName,txtTitle,txtWords传递到本地存储中。<form >
<p>收件人:</p>
<select name="课程性质" id="txtName">
<option value="全体师生">全体师生</option>
<option value="a老师">a老师</option>
<option value="b学生">b学生</option>
</select>
<input type="text" name="txtName" id="txtName" required/>
<p>内容:</p>
<textarea type="text" name="txtTitle" id="txtTitle" required rows="10" cols="80"/>
</textarea>
<p>发信人:</p><p id="txtWords"></p>
<br />
<input type="button" value="发送" id="btnSave" class="button"/>
<input type="button" value="重置" id="btnSave" class="button"/>
</form>$(function () {
initDatabase();
$("#btnSave").click(function () {
var txtName = $("#txtName").val();
var txtTitle = $("#txtTitle").val();
var txtWords = $("#txtWords").val();
var db = getCurrentDb();
//插入数据
db.transaction(function (trans) {
trans.executeSql("insert into Demo(uName,title,words) values(?,?,?) ", [txtName, txtTitle, txtWords], function (ts, data) {
}, function (ts, message) {
alert(message);
});
});
hidedata();
showAllTheData();
});
});
function initDatabase() {//初始化数据库
var db = getCurrentDb();
if(!db) {
alert("您的浏览器不支持HTML5");
return;
}
db.transaction(function (trans) {
trans.executeSql("create table if not exists Demo(uName text null,title text null,words text null)", [], function (trans, result) {
}, function (trans, message) {
alert(message);
});
}, function (trans, result) {
}, function (trans, message) {
});
}
function getCurrentDb() {
//打开数据库,或者直接连接数据库参数:数据库名称,版本,概述,大小
var db = openDatabase("myDb", "1.0", "it's to save demo data!", 1024 * 1024); ;
return db;
}
function showAllTheData() {
$("#tblData").empty();
var db = getCurrentDb();
db.transaction(function (trans) {
trans.executeSql("select * from Demo ", [], function (ts, data) {
if (data) {
for (var i = 0; i < data.rows.length; i++) {
appendDataToTable(data.rows.item(i));//获取某行数据的json对象
}
}
}, function (ts, message) {
alert(message);
var tst = message;
});
});
}
function appendDataToTable(data) {//将数据展示到表格里面
//uName,title,words
var txtName = data.uName;
var txtTitle = data.title;
var words = data.words;
var strHtml = "";
strHtml += "<tr>";
strHtml += "<td>"+txtName+"</td>";
strHtml += "<td>" + txtTitle + "</td>";
strHtml += "<td>" + words + "</td>";
strHtml += "</tr>";
$("#tblData").prepend(strHtml);
}
function hidedata(){
$("#txtTitle").empty();
alert("信息已发送。");
}上面是关于html5本地数据库调用。txtWords的值是由url传递过来的:function url2object(str) {
if(!str) {
str = window.location.search;
}
str = str.substring(1); // 去掉问号
var keyVals = str.split('&'); // 按&分割
var params = {};
for (var i = 0; i < keyVals.length; i++) {
var keyVal = keyVals[i]; // 按照=分割
var splitIndex = keyVal.indexOf('=');
if (splitIndex !== -1) {
params[keyVal.substring(0, splitIndex)] = keyVal.substring(splitIndex + 1);
}
}
var helloword="欢迎您,"+str;
$('#name-motion').text(helloword);
$('#txtWords').text(str);
return params;
}调试的时候发现txtWords怎么都传不上数据库。求大神看一下!谢谢!
添加回答
举报
0/150
提交
取消