我的onDeviceReady事件没有触发android phonegap?

时间:2014-08-26 09:39:08

标签: javascript android jquery html cordova

我有2个问题 1.我的onDeviceReady事件没有在我的代码中触发,因为我尝试了很多次plzz帮助我

并告诉我如何将select语句输出设置为变量,if-else可以进一步使用

----------------------------------------------- -------------------------------------------- enter code here < / p>

      <!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8" />

    <title>Responsive Image Maps jQuery Plugin</title>
    <meta name="HandheldFriendly" content="True" />

    <meta name="MobileOptimized" content="320" />


    <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1" />

    <link rel="stylesheet" type="text/css" href="css/styles.css"/>

    <link rel="stylesheet" href="jquery.mobile-1.3.1.min.css">


    <script type="text/javascript" charset="utf-8" src="js/jquery-1.11.1.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.rwdImageMaps.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/phonegap-1.1.0.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

    <script src="js/ios-orientationchange-fix.min.js"></script>

    <script>
        alert("1scrptt");

        var i;
        var finall;
        var flen
        function myfun()
        {
            var h=window.innerHeight;
            var w= window.innerWidth;
            document.getElementById("homeimg").style.height=(h-22)+"px";
            document.getElementById("homeimg").style.width=w+"px";
        }
    </script>


    <script type="text/javascript" charset="utf-8">

        jQuery(document).ready(function(){

            document.addEventListener("deviceready", onDeviceReady, false);
            alert("llloo");

            db = window.openDatabase("ThemeDB", "1.0", "ThemeNY", 200000);
            alert("ready");

            function onDeviceReady() {
                alert("helllloo");
                db.transaction(populateDB,successCB);
            }
            function populateDB(tx) {

                // tx.executeSql('DROP TABLE IF EXISTS Table_NY');
                tx.executeSql('CREATE TABLE IF NOT EXISTS Table_NY (id INTEGER PRIMARY KEY AUTOINCREMENT,value INTEGER)');
                //tx.executeSql( 'SELECT value FROM Table_NY where id = 1' );
                tx.executeSql('INSERT INTO Table_NY (value) VALUES (1)');
                //tx.executeSql('INSERT INTO Table_NY (value) VALUES (2)');
                //tx.executeSql('SELECT value FROM Table_NY where id = 1', [], successCB);

                db.transaction(queryDB);}
            //tx.executeSql('INSERT INTO Table_NY (id, data) VALUES (1, "First row")');
            //tx.executeSql('INSERT INTO Table_NY (id, data) VALUES (2, "Second row")');
            // valueGB=results.row.item(value);

            function successCB() {
                var db = window.openDatabase("ThemeDB", "1.0", "ThemeNY", 200000);
                db.transaction(queryDB);
            }

            function queryDB(tx) {
                tx.executeSql('SELECT value FROM Table_NY where id = 1', [], querySuccess);

            }
            //function queryDB(tx) {

            //  }

            // Query the success callback
            //
            //  function querySuccess(tx, results) {

            //  }
            /*  var querySql = function(sql) {
             var df = $.Deferred();
             tx.executeSql('SELECT value FROM Table_NY where id = 1',[],sucessCB,                errCB);
             function sucessCB(tx, results){  //<--- this results param
             var tab = [];
             for(i=0;i<results.length;i++){
             tab.push(results.row.item(i))
             }
             df.resolve(tab);``
             }
             function errCB(tx, e) {
             df.reject(e);
             }*/
            function querySuccess(tx, results)
            {
                var len = results.rows.length;
                console.log("Table_NY" + len + " rows found.");
                for (var i=0; i<len; i++){
                    console.log("Row = " + i + " ID = " + results.rows.item(i).value);
                }
                finall=results.rows.item(0).value;
                alert(finall);


                //querySql('SELECT value FROM Table_NY where id = 1').done(function(result) {
                //console.log(result); 
                //}

                /*function successCB(tx, results) {
                 flen=results.row.item(0);
                 len = results.rows.length;
                 n  finall = [];
                 for(i=0;i<len;i++)
                 {
                 finall.push(results.row.item(i))
                 }

                 //len = results.rows.length;
                 // console.log("Table_NY" + valueGB + " rows found.");
                 // for (var i=0; i<valueGB; i++){
                 //     console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data =  " +                                              results.rows.item(i).data);
                 // }*/
                if(finall == 0)
                {
                    window.setTimeout(function () {

                        window.location.href = "home.html";

                    }, 10000);
                }
                else if (finall == 1)
                {
                    window.setTimeout(function () {

                        window.location.href = "homeb.html";

                    }, 10000);
                }

                else
                {
                    window.location.href = "setting.html";
                }

                $('img[usemap]').rwdImageMaps();
                /*
                 $('area').on('click', function() {
                 alert($(this).attr('alt') + ' clicked');
                 });*/

            }
        });
    </script>

</head>
<style>
    body {
        font-family: Helvetica, Arial, sans-serif;
    }
    h1 {
        font-size: 20px;
    }
    div {
        width: 100%;
    }
    img[usemap] {
        border: none;
        height: auto;
        max-width: 100%;
        width: auto;
    }
</style>
<body on onLoad="myfun();" onResize="myfun();">

    <div class="landscape">
        <img id="homeimg" src="img/splash_l.png" width="1024" height="768"  usemap="#powerpuffgirls" alt="" />
    </div>

    <div class="portrait">
        <img id="homeimg" src="img/splash_p.png" width="768" height="1024"  usemap="#powerpuffgirls" alt="" />
    </div>
</body>
</html>

请帮助我

1 个答案:

答案 0 :(得分:0)

我希望您不要在浏览器中尝试使用document.addEventListener(“deviceready”,onDeviceReady,false):D

如果没有,请进行测试:

<script>
 document.addEventListener("deviceready", function(){
alert("it works");
}, false);
</script