我创建了我的应用程序XDK HTML5,并在" EMULATOR"中测试了我的应用程序。并且工作完美,当我生成APK并在不同的设备上测试时,任何javascript函数都不起作用。请帮忙
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="jqm/jquery.mobile-min.css">
<link rel="stylesheet" type="text/css" href="css/index_main.less.css" class="main-less">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<script src="intelxdk.js"></script>
<script src="cordova.js"></script>
<script src="xhr.js"></script>
<script src="xdk/init-dev.js"></script>
<script type="application/javascript" src="lib/jquery.min.js"></script>
<script type="application/javascript" src="jqm/jquery.mobile-min.js" data-ver="0"></script>
<script type="text/javascript">
$(document).ready(function(){
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
var request, db;
if(!window.indexedDB)
{
intel.xdk.notification.alert("No soporta IndexedDB", "Mensaje", "Ok");
}
else
{
request = window.indexedDB.open("testDB1", 2);
request.onerror = function(event){
console.log("Error al abrir la DB", event);
}
request.onupgradeneeded = function(event){
db = event.target.result;
var objectStore = db.createObjectStore("students", { keyPath : "rollNo" });
};
request.onsuccess = function(event){
intel.xdk.notification.alert("Si soporta IndexedDB", "Mensaje", "Ok");
db = event.target.result;
}
}
$("#addBtn").click(function(){
var name = $("#name").val();
var rollNo = $("#rollno").val();
var precio = $("#precio").val();
var transaction = db.transaction(["students"],"readwrite");
transaction.oncomplete = function(event) {
intel.xdk.notification.alert("Se ingreso a la DB IndexedDB", "Mensaje", "Ok");
};
transaction.onerror = function(event) {
intel.xdk.notification.alert("Error al grabar", "Mensaje", "Ok");
};
var objectStore = transaction.objectStore("students");
objectStore.add({rollNo: rollNo, name: name, precio: precio});
$("#name").val("");
$("#rollno").val("");
$("#precio").val("");
});
$("#btnBuscarE").click(function(){
var rollNo = $("#rollnoE").val();
var request = db.transaction(["students"],"readwrite").objectStore("students").get(rollNo);
request.onsuccess = function(event){
$("#rollnoE").val(request.result.rollNo);
$("#nameE").val(request.result.name);
$("#precioE").val(request.result.precio);
};
});
$("#btnModificarE").click(function(){
var name = $("#nameE").val();
var rollNo = $("#rollnoE").val();
var precio = $("#precioE").val();
var transaction = db.transaction(["students"],"readwrite");
var objectStore = transaction.objectStore("students");
var request = objectStore.get(rollNo);
request.onsuccess = function(event){
request.result.rollNo = rollNo;
request.result.name = name;
request.result.precio = precio;
objectStore.put(request.result);
};
intel.xdk.notification.alert("Se actualizo correctamente el producto", "Mensaje", "Ok");
$("#nameE").val("");
$("#rollnoE").val("");
$("#precioE").val("");
});
$("#btnBuscarD").click(function(){
var rollNo = $("#rollnoD").val();
var request = db.transaction(["students"],"readwrite").objectStore("students").get(rollNo);
request.onsuccess = function(event){
$("#rollnoD").val(request.result.rollNo);
$("#nameD").val(request.result.name);
$("#precioD").val(request.result.precio);
};
});
$("#btnEliminarD").click(function(){
var rollNo = $("#rollnoD").val();
db.transaction(["students"],"readwrite").objectStore("students").delete(rollNo);
intel.xdk.notification.alert("Se elimino correctamente el producto", "Mensaje", "Ok");
$("#nameD").val("");
$("#rollnoD").val("");
$("#precioD").val("");
});
$("#removeBtn").click(function(){
var rollNo = $("#rollno").val();
db.transaction(["students"],"readwrite").objectStore("students").delete(rollNo);
});
$("#getBtn").click(function(){
var rollNo = $("#rollno").val();
var request = db.transaction(["students"],"readwrite").objectStore("students").get(rollNo);
request.onsuccess = function(event){
$("#result").html("Name : "+request.result.name);
};
});
$("#updateBtn").click(function(){
var rollNo = $("#rollno").val();
var name = $("#name").val();
var transaction = db.transaction(["students"],"readwrite");
var objectStore = transaction.objectStore("students");
var request = objectStore.get(rollNo);
request.onsuccess = function(event){
$("#result").html("Updating : "+request.result.name + " to " + name);
request.result.name = name;
objectStore.put(request.result);
};
});
$("#ShowAll").click(function(){
document.getElementById('resultado').innerHTML = "";
var objectStore = db.transaction(['students'], "readonly").objectStore('students');
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
var message = "<ul style='margin: 1em 0 1em -1em;'>";
message += "<a href='#' id=''>" + cursor.value.rollNo + "</a> : " + cursor.value.name + " / " + cursor.value.precio + "<br />";
document.getElementById('resultado').innerHTML += message;
cursor.continue();
}
else {
message += "</ul>";
};
};
});
});
</script>
</head>
<body>
<div class="upage ui-page-theme-b" id="mainpage" data-role="page">
<div class="upage-outer">
<div data-role="header" class="container-group inner-element uib_w_1" data-uib="jquery_mobile/header" data-ver="0" data-position="fixed">
<h1>Inventario</h1>
<div class="widget-container wrapping-col single-centered"></div>
<div class="widget-container content-area horiz-area wrapping-col left"></div>
<div class="widget-container content-area horiz-area wrapping-col right"></div>
</div>
<div class="upage-content content-area vertical-col left" id="page_36_19">
<div class="widget uib_w_25 d-margins AAA" data-uib="media/text" data-ver="0">
<div class="widget-container left-receptacle"></div>
<div class="widget-container right-receptacle"></div>
<div>
<p>DERECHOS DE AUTOR</p>
<p>ALLEN BRICEÑO PALACIOS.</p>
</div>
</div>
<div data-role="collapsible" class="no_wrap widget uib_w_2" data-uib="jquery_mobile/collapsible" data-ver="0" data-collapsed="true">
<h4>Añadir Producto</h4>
<div class="col uib_col_1 single-col" data-uib="layout/col" data-ver="0">
<div class="widget-container content-area vertical-col">
<div class="table-thing with-label widget uib_w_10 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="rollno">Codigo</label>
<input class="wide-control" placeholder="Ingrese Codigo" type="text" id="rollno">
</div>
<div class="table-thing with-label widget uib_w_11 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="name">Producto</label>
<input class="wide-control" placeholder="Ingrese Producto" type="text" id="name">
</div>
<div class="table-thing with-label widget uib_w_12 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="precio">Precio</label>
<input class="wide-control" placeholder="Ingrese el precio" type="number" id="precio">
</div><span class="uib_shim"></span>
</div>
</div>
<a class="widget uib_w_9 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button" data-mini="true" id="addBtn">Añadir</a>
</div>
<div data-role="collapsible" class="no_wrap widget uib_w_3" data-uib="jquery_mobile/collapsible" data-ver="0" data-collapsed="true">
<h4>Editar Producto</h4>
<div class="col uib_col_2 single-col" data-uib="layout/col" data-ver="0">
<div class="widget-container content-area vertical-col">
<div class="table-thing with-label widget uib_w_13 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="rollnoE">Codigo</label>
<input class="wide-control" placeholder="Ingrese codigo" type="text" id="rollnoE">
</div>
<div class="table-thing with-label widget uib_w_14 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="nameE">Producto</label>
<input class="wide-control" placeholder="Producto" type="text" id="nameE">
</div>
<div class="table-thing with-label widget uib_w_15 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="precioE">Precio</label>
<input class="wide-control" placeholder="Precio" type="number" id="precioE">
</div><a class="widget uib_w_16 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button" data-mini="true" id="btnBuscarE">Buscar Codigo</a><a class="widget uib_w_17 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button"
data-mini="true" id="btnModificarE">Modificar</a><span class="uib_shim"></span>
</div>
</div>
</div>
<div data-role="collapsible" class="no_wrap widget uib_w_4" data-uib="jquery_mobile/collapsible" data-ver="0" data-collapsed="true">
<h4>Eliminar Producto</h4>
<div class="col uib_col_3 single-col" data-uib="layout/col" data-ver="0">
<div class="widget-container content-area vertical-col">
<div class="table-thing with-label widget uib_w_20 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="rollnoD">Codigo</label>
<input class="wide-control" placeholder="Ingrese codigo" type="text" id="rollnoD">
</div>
<div class="table-thing with-label widget uib_w_21 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="nameD">Producto</label>
<input class="wide-control" placeholder="Producto" type="text" id="nameD">
</div>
<div class="table-thing with-label widget uib_w_22 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline" for="precioD">Precio</label>
<input class="wide-control" placeholder="Precio" type="text" id="precioD">
</div><a class="widget uib_w_23 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button" data-mini="true" id="btnBuscarD">Buscar Codigo</a><a class="widget uib_w_24 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button"
data-mini="true" id="btnEliminarD">Eliminar</a>
<span class="uib_shim"></span>
</div>
</div>
</div>
<div data-role="collapsible" class="no_wrap widget uib_w_5" data-uib="jquery_mobile/collapsible" data-ver="0" data-collapsed="true">
<h4>Ver Productos</h4>
<div class="col uib_col_4 single-col" data-uib="layout/col" data-ver="0">
<div class="widget-container content-area vertical-col">
<a class="widget uib_w_18 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button" data-mini="true" id="ShowAll">Actualizar</a>
<div class="widget uib_w_19 d-margins qs" data-uib="media/text" data-ver="0" id="resultado">
<div class="widget-container left-receptacle"></div>
<div class="widget-container right-receptacle"></div>
</div><span class="uib_shim"></span>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
我requerid使用IndexedDB,在app中使用本地数据库;我测试构建交叉和Android版本而不工作。
答案 0 :(得分:0)
仿真器只是对真实设备的粗略近似。我建议尝试“调试”选项卡,这将允许您远程调试USB连接设备。这应该更像是在设备上运行构建的应用程序,特别是如果它已经在模拟器中工作,这表明您不依赖于该配置中不支持的任何插件。如果没有别的,这至少应该告诉你它失败的地方,这将使你能够提出更详细的问题。
您还应该检查以确保在项目页面中包含所需的所有插件。模拟器通常会这样做,但在仿真方面可能并不完美。