簡體   English   中英

在使用JQueryMobile和IBM Worklight 6.0時找不到$

[英]can't find $ - while using JQueryMobile and IBM Worklight 6.0

我正在嘗試將條形碼掃描儀集成到在工作燈上開發的手機間隙應用程序中,當前的html頁面來自主頁面的href,就像這樣。

<a data-role="button" href="itemscan.html" rel="external" data-shadow="false"
    data-theme="none"><img src="images/dashboard_barcode.png"  ></a>

我的HTML頁面:

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
<head>
<title>BarCode Scanner</title>
            <link rel="stylesheet" href="jqueryMobile/jquery/jquery.mobile-1.3.2.css">
            <script src="jqueryMobile/jquery/jquery.mobile-1.3.2.js"></script>


</head>
    <body>
        <div class="app">
            <h1>Zxing Scanner!!</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
                <p id="barcoderesult">Bar Code Result: Nil</p>

            </div>
        </div>
        <script type="text/javascript" src="js/cordova-2.5.0.js"></script>
        <script type="text/javascript" src="modules/core/CoreFunc.js"></script>
        <script type="text/javascript" src="js/barcodescanner.js"></script>
        <script type="text/javascript" src="js/itemscan.js"></script>
        <script type="text/javascript" src="js/MenuPanel.js"></script>
        <script type="text/javascript">
            app.initialize();
       </script>
    </body>
</html>

JS檔案:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        // demo the scan
        console.log('about to scan');
        try {
            var scanned = app.scan();
            console.log('scan triggered', scanned);
        } catch (e) {
            console.log('scan failed');
            console.log(JSON.stringify(e));
            console.log('that sucks... reloading in 10');
            setTimeout(function() {
                console.log('reloading now...');
                app.onDeviceReady();
            }, 10000);
        }
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },
    /**
     * here is an example for scanning a barcode...
     * obviously, your own JS logic <<here>>
     *
     * Note the require() method is called on window.cordova
     *   this is different than the readme!
     */
    scan: function() {

        console.log('scan(): init');
        // documentation said the syntax was this:
        // var scanner = window.PhoneGap.require("cordova/plugin/BarcodeScanner");
        // but playing with options, seems like it should be this:
        var scanner = window.cordova.require("cordova/plugin/BarcodeScanner");
        scanner.scan(
                function (result) {

                    var parentElement = document.getElementById("barcoderesult");
                    parentElement.innerHTML = result.text;
//                    alert("We got a barcode\n" +
//                        "Result: " + result.text + "\n" +
//                        "Format: " + result.format + "\n" +
//                        "Cancelled: " + result.cancelled);
                    console.log("We got a barcode\n" +
                            "Result: " + result.text + "\n" +
                            "Format: " + result.format + "\n" +
                            "Cancelled: " + result.cancelled);
                  $.mobile.changePage( "../itemDetails.html", { transition: "slideup", changeHash: false });

                },
                function (error) {
                    alert("Scanning failed: " + error);
                }
                );
    }
};

掃描工作正常,成功回調后,我得到條形碼,然后我得到這個,我無法做changePage。

[LOG]錯誤回調錯誤:BarcodeScanner957715450 = ReferenceError:找不到變量:$

從我所做的所有搜索中,我發現jQuery沒有正確加載。 我是所有這些網絡技術的新手,所以任何幫助表示贊賞。

Can't find variable: $ jquery沒有加載到你的代碼中。 請確保正確加載jquery並且沒有如Gamex所述的jquery沖突。

window.onload = function() {
    if (window.jQuery) {        
    alert("jQuery is loaded  !");
    } else {        
    alert("jQuery is not loaded");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM