为什么我的jQuery Mobile代码不起作用?

时间:2017-12-09 13:02:14

标签: jquery cordova jquery-mobile

我不确定如何在我的移动设备上制作任何jQuery移动事件,如tap或touchstart。当我在桌面上运行它时,一切正常。使用PhoneGap构建apk。

根据jQuery移动文档,代码应该在移动设备上运行。试图在移动设备上调试它,似乎jquery甚至不加载......

sap.ui.define(["sap/ui/core/mvc/Controller", "sap/m/MessageToast", "sap/m/MessageBox", "sap/ui/core/routing/History"], function(
    Controller, MessageToast, MessageBox, History) {
  "use strict";

  return Controller.extend("cafeteria.controller.EmployeeFileUpload", {
    onNavBack: function() {
      var oHistory = History.getInstance();
      var sPreviousHash = oHistory.getPreviousHash();
      if (sPreviousHash !== undefined) {
        window.history.go(-1);
      } else {
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        oRouter.navTo("admin", true);
      }
    },
    handleTypeMissmatch: function(oEvent) {
      var aFileTypes = oEvent.getSource().getFileType();
      jQuery.each(aFileTypes, function(key, value) {
        aFileTypes[key] = "*." + value;
      });
      var sSupportedFileTypes = aFileTypes.join(", ");
      MessageToast.show("The file type *." + oEvent.getParameter("fileType") +
        " is not supported. Choose one of the following types: " +
        sSupportedFileTypes);
    },
    handleValueChange: function(oEvent) {
      MessageToast.show("Press 'Upload File' to upload file '" + oEvent.getParameter("newValue") + "'");
    },
    handleFileSize: function(oEvent) {
      MessageToast.show("The file size should not exceed 10 MB.");
    },
    handleFileNameLength: function(oEvent) {
      MessageToast.show("The file name should be less than that.");
    },
    onUpload: function(e) {
      var oResourceBundle = this.getView().getModel("i18n").getResourceBundle();
      var fU = this.getView().byId("idfileUploader");
      var domRef = fU.getFocusDomRef();
      var file = domRef.files[0];
      var reader = new FileReader();
      var params = "EmployeesJson=";
      reader.onload = function(oEvent) {
        var strCSV = oEvent.target.result;
        var arrCSV = strCSV.match(/[\w .]+(?=,?)/g);
        var noOfCols = 6;
        var headerRow = arrCSV.splice(0, noOfCols);
        var data = [];
        while (arrCSV.length > 0) {
          var obj = {};
          var row = arrCSV.splice(0, noOfCols);
          for (var i = 0; i < row.length; i++) {
            obj[headerRow[i]] = row[i].trim();
          }
          data.push(obj);
        }
        var Len = data.length;
        data.reverse();
        params += "[";
        for (var j = 0; j < Len; j++) {
          params += JSON.stringify(data.pop()) + ", ";
        }
        params = params.substring(0, params.length - 2);
        params += "]";
        // MessageBox.show(params);
        var http = new XMLHttpRequest();
        var url = oResourceBundle.getText("UploadEmployeesFile").toString();
        http.onreadystatechange = function() {
          if (http.readyState === 4 && http.status === 200) {
            var json = JSON.parse(http.responseText);
            var status = json.status.toString();
            switch (status) {
              case "Success":
                MessageToast.show("Data is uploaded succesfully.");
                break;
              default:
                MessageToast.show("Data was not uploaded.");
            }
          }
        };
        http.open("POST", url, true);
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.send(params);
      };
      reader.readAsBinaryString(file);
    }
  });
});
* {
  margin: 0;
  padding: 0
}

body {
  background-color: red;
}

h1 {
  position: absolute;
  right: 30px;
  padding: 30px;
  color: white;
  text-shadow: none;
}

#hello {
  z-index: 3;
  background-color: #222222;
}

#hello > div {
  height: 200px;
  width: 200px;
  background-color: green;
}

.ui-page { background:transparent; }

.ui-input-text {
  border: none;
}


<!-- begin snippet: js hide: false console: true babel: false -->

1 个答案:

答案 0 :(得分:0)

在Cordova或PhoneGap应用程序中的

使用您将要发布的应用程序的www目录中的jQuery,然后将其包括在内,例如:

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

而不是来自cdn或远程地址,例如:https://code.jquery.com