我已经通过本教程:http://www.mobilehtml5.com/post/401111526/tutorial-your-first-mobile-html5-app-offline-storageHTML 5脱机的SQLite数据库
我一直在使用它来创建一个简单的数据库来记录钱街机,与表中存储的名称和数量在每台机器中。
我的问题是,我不知道最好的方法来轻松地编辑行? html5rocks.com给了我几个想法,但没有什么合适的。
任何人都可以把我放在正确的轨道上吗?我不知道正确的方法,是否有某种类型的游标类型的做法?或者我应该有一个循环加载到输入表单框中的值,然后更新这些?
任何帮助将是辉煌的,我已经包含在下面的代码,所以你可以看到我在做什么。
<!DOCTYPE html>
<html>
<head>
<title>Machine Total Calculator</title>
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.4.1");
</script>
<script>
var db = window.openDatabase("Machines", "", "Arcade Machines", 1024*1000);
function insertMachine(name, amount) {
db.transaction(function(tx) {
tx.executeSql('INSERT INTO groupOne (name, amount) VALUES (?, ?)', [name, amount]);
});
}
function renderResults(tx, rs) {
e = $('#status');
e.html("");
for(var i=0; i < rs.rows.length; i++) {
r = rs.rows.item(i);
e.html(e.html() + 'id: ' + r['id'] + ', Name: ' + r['name'] + ', Amount: ' + r['amount'] + '<br>');
}
}
function renderRecords(name) {
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM groupOne', [], renderResults);
});
}
$(document).ready(function() {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS groupOne(id INTEGER PRIMARY KEY, name TEXT, amount DECIMAL)', []);
});
$('#machine_form').submit(function() {
insertMachine($('#name').val(), $('#amount').val());
renderRecords();
return false;
});
renderRecords();
});
</script>
</head>
<body>
<form method="get" id="machine_form">
<div>
<input type="name" id="name" placeholder="Enter Machine Name" size="30"/>
<input type="number" current id="amount" placeholder="Amount" name="amount" size="15" />
<input type="submit" value="Add Machines" />
</div>
</form>
<div id="status">
</div>
</body>
</html>
好的,所以我想添加一个按钮,打印出哪些行通过ID更新功能,并添加编辑和更新内的能力?我试过这个,但是id不会传递给函数:e.html(e.html()+'id:'+ r ['id'] +',Name:'+ r ['name']] +',金额:'+ r ['金额'] +'e'+'
'); } – mark 2011-02-27 15:34:26