繁体   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