0
我在html5中使用SQLite,它工作正常。但事情是,我在页面中显示的行看起来并不好。我用innerhtml来显示用户插入的行。 这里是脚本通过JavaScript生成表格
function showRecords() {
results.innerHTML = '';
// This function needs a single argument, which is a function that takes
// care of actually executing the query
db.transaction(function(tx) {
tx.executeSql(selectAllStatement, [], function(tx, result) {
dataset = result.rows;
for (var i = 0, item = null; i < dataset.length; i++) {
item = dataset.item(i);
results.innerHTML += '<li>' + item['lastName'] + ' , '
+ item['firstName']
+ ' <a href="#" onclick="loadRecord(' + i
+ ')">edit</a> '
+ '<a href="#" onclick="deleteRecord(' + item['id']
+ ')">delete</a></li>';
}
});
});
}
/**
* Loads the record back to the form for updation
*
* @param i
*/
function loadRecord(i) {
var item = dataset.item(i);
firstName.value = item['firstName'];
lastName.value = item['lastName'];
phone.value = item['phone'];
id.value = item['id'];
}
/**
* Delete a particular row from the database table with the specified Id
*
* @param id
*/
function deleteRecord(id) {
db.transaction(function(tx) {
tx.executeSql(deleteStatement, [ id ], showRecords, onError);
});
resetForm();
}
所以在代码showRecords()
方法,我已经硬编码要显示的数据。我想要的是,数据应该以正确的表格格式显示。我知道我必须在JavaScript中为动态表格生成创建元素,但我无法这样做,也显示表格中的内容。
每次用户填写表单并单击插入按钮,插入语句执行,然后调用方法showRecords()
。我无法弄清楚正确的解决方案。
是jQuery的允许吗? – bezmax