下面的代码用于需要将一些值保存到本地存储中的表单,我已经让它在浏览器中工作,但是当我在 xcode/cordova 中加载这个东西时,它不会触发该功能。我尝试调试,因此有很多很多警报,我在 DWCS6 中尝试使用实时视图,但无济于事,我似乎无法让它运行。你能找到错误吗?
该函数saveSpanning()
有一个 if 循环,当它退出 if-then-else 循环时,它不会在 xcode 模拟器中继续。在浏览器中它会继续。
更新:做什么:有一个滑块,它产生一个值,这个值需要与其他两个值(由 JavaScript 生成)一起保存在本地存储中,即:日期和记录计数。所以总共三个值。
脚本运行,使用 jquery mobile,启动此功能的按钮有效,我使用document.ready
了onBodyLoad
,它基本上有效,但该功能saveSpanning
在 phonegap/ios/xcode 模拟器或设备中没有更进一步。
function saveSpanning() {
alert("saveSpanning gestart!");
var inputSpanning = document.getElementById("valSliderSpanning").value;
alert("input spanning = " + inputSpanning);
//For Time
var mes_time = document.getElementById("tijdSpanning").value;
var mestimearr = mes_time.split(":");
//For Date
var mes_date = document.getElementById("datumSpanning").value;
var mesdatearr = mes_date.split("-");
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
var curr_hours = d.getHours();
var curr_min = d.getMinutes();
var curr_sec = d.getSeconds();
//newDate = curr_year + "/" + curr_month + "/" + curr_date + " " + curr_hours + ":" + curr_min + ":" + curr_sec
// origienel opmaak datum newDate = mesdatearr[0] + "/" + mesdatearr[1] + "/" + mesdatearr[2] + " " + mestimearr[0] + ":" + mestimearr[1] + ":00";
newDate = mesdatearr[0] + "/" + mesdatearr[1] + "/" + mesdatearr[2];
alert("deze datum wordt opgelsage: " + newDate);
//var itemId = newDate.getTime(); //creates a unique id with the milliseconds since January 1, 1970
var itemId = "spanningKey";
var values = new Array();
values.push(newDate); //push each value into our values array
values.push(inputSpanning); //push each value into our values array
//alert(inputSpanning);
var spanningCountVal = localStorage.getItem('spanning_count');
//alert(spanningCountVal);
if (spanningCountVal == null) {
spanningCountVal = 1;
alert("spanningCountVal was null, en wordt dus nu 1: " + spanningCountVal);
}
else {
spanningCount = parseInt(spanningCountVal) + 1;
alert("zit nu in de else loop: " + spanningCount);
}
alert("uit de ifthenelseloop, spanningCount = " + spanningCount);
itemId = itemId + '-rec-' + spanningCount;
alert("itemid: " + itemId);
alert("spanningCountVal: " + spanningCount);
localStorage.setItem("spanning_count", spanningCount); //store the item in the database
localStorage.setItem(itemId, values.join("|")); //store the item in the database
alert("Successfully Saved.");
}
$(document).ready(function() {
$("#button").click(function() {
alert("hallo functie");
});
$("p").text("The DOM is now loaded and can be manipulated.");
$('#button2').click(function() {
alert('Button has been clicked');
});
$('#knopje').click(function() {
saveSpanning();
});
});