0

我正在学习 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 is not defined”

4

0 回答 0