首先您需要创建一个数组,将此数组存储在 localStarage 中,例如到第 1 页将两个值存储在数组中,并在选择的每一页上更新您的 localStorage 值,在最后一页使用 org.apache.cordova.file 插件将此 localStorage 值写入文件。我做了例子,你可以根据你的要求来管理。
a.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="page_a">
<div data-role="header" class="">
<h3>Fruit</h3>
</div>
<div role="main" id="" class="ui-content">
<div class="ui-field-contain">
<fieldset data-role="controlgroup">
<input type="checkbox" name="apple" id="apple" value="Apple" >
<label for="apple">Apple</label>
<input type="checkbox" name="orange" id="orange" value="Orange">
<label for="orange">Orange</label>
</fieldset>
</div>
<a href="" data-ajax="false" id="btn_a" class="ui-btn ui-mini">Book Order</a>
</div>
</div>
</body>
<script>
var arr_fruit = [];
$("#btn_a").on("click", function(event){
$("input[type=checkbox]:checked").each(function(key){
arr_fruit.push( $(this).val());
});
localStorage.setItem("arr_fruit", arr_fruit);
location.href = "c.html";
})
</script>
<html>
b.html
<div data-role="page" id="page_b">
<div data-role="header" class="">
<h3>Flowers</h3>
</div>
<div role="main" id="" class="ui-content">
<div class="ui-field-contain">
<fieldset data-role="controlgroup">
<input type="checkbox" name="rose" id="rose" value="Rose" >
<label for="rose">Rose</label>
<input type="checkbox" name="sunflower" id="sunflower" value="Sunflower">
<label for="sunflower">Sunflower</label>
</fieldset>
</div>
<a href="" data-ajax="false" id="btn_b" class="ui-btn ui-mini">Book Order</a>
</div>
</div>
<script>
var arr_flow = [];
$("#btn_b").on("click", function(event){
$("input[type=checkbox]:checked").each(function(key){
arr_flow.push( $(this).val());
});
localStorage.setItem("arr_flow", arr_flow);
location.href = "c.html";
})
</script>
c.html
<div data-role="page" id="page_c">
<div data-role="header" class="">
<a href="a.html" data-ajax="false" id="btn_b" class="ui-btn ui-mini ui-btn-left">Page A</a>
<h3>Details</h3>
<a href="b.html" data-ajax="false" id="btn_b" class="ui-btn ui-mini ui-btn-right">Page B</a>
</div>
<div role="main" id="" class="ui-content">
<p id="fr_title" style="display:none"><h3>Fruits</h3> </p>
<ul data-role="listview" id="list_fruit"></ul>
<p id="fl_title" style="display:none"><h3>Flowers</h3> </p>
<ul data-role="listview" id="list_flow"></ul>
</div>
</div>
<script>
var list_fruit = "";
var arr_fruit = localStorage.getItem("arr_fruit").split(",");
var list_flow = "";
var arr_flow = localStorage.getItem("arr_flow").split(",");
$("#page_c").on("pageshow", function(event){
// Fruits
$("#fr_title").show();
$.each(arr_fruit, function(key, value){
list_fruit += '<li>'+value+'</li>';
});
$("#list_fruit").html(list_fruit).trigger("create");
$("#list_fruit").listview( "refresh" );
// Flowers
$("#fl_title").show();
$.each(arr_flow, function(key, value){
list_flow += '<li>'+value+'</li>';
});
$("#list_flow").html(list_flow).trigger("create");
$("#list_flow").listview( "refresh" );
});
</script>