HTML5,关于本地数据库的问题

时间:2013-01-17 15:43:27

标签: database html5 local

我正在学习HTML 5 /本地数据库。当我试图使用它时,我遇到了奇怪的错误。请帮忙。感谢提前

 <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">

    var db = openDatabase("DB_Comments", "", "", 102400);
    db.transaction(function (tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS Comments(name TEXT, msg TEXT, time INTEGER)", []);
    });

    function SaveComments() {
        var name = jQuery("#txtName").val();
        var comments = jQuery("#txtComments").val();
        var time = new Date().toGMTString();

        db.transaction(function (tx) {
            tx.executeSql("INSERT INTO Comments VALUES (?,?,?)", [name, comments, time], function (tx, rs) { alert("DONE!"); }, function (tx, error) { alert(error); });
        });

        LoadComments();
    }

    function LoadComments() {
        var result = "";
        db.transaction(function (tx) {
            tx.executeSql("SELECT * FROM Comments", [], function (tx, rs) {
                for (var i = 0; i < rs.rows.length; i++) {
                    result = result + "<tr><td>" + rs.rows[i].time + "</td><td>" + rs.rows[i].name + "</td><td>" + rs.rows[i].comments + "</td></tr>";
                }
            });
        });
        jQuery("#commentslist").html(result);
    }

    jQuery(document).ready(function () {

    });
</script>

然后我在Chrome版本24.0.1312.52 m中运行了这个;我无法上传IMG,所以只需将errr msg放在这里:“tx:Exception:ReferenceError:tx未定义”

0 个答案:

没有答案