2
我一直堅持到這..我jquery的頁面上運行,根據價值用戶放在同一頁面上顯示結果。它的工作正常,但我不想顯示,但在下一頁上。
如何做到這一點?
我聽說通過ajax調用我可以給結果給PHP,並可以存儲在那裏,但我不知道如何做到這一點,或者如果有簡單的方法呢?如何存儲jQuery函數的結果並將其顯示在其他頁面上
<form method="post">
<div class="form-group row">
<label for="age" class="col-sm-7">• What is the age of the oldest person applying? </label>
<div class="col-sm-10">
<select type="age" class="form-control form-control-sm" id="age" name="age">
<option value="" selected="" disabled="">Please Select</option>
<option value="Under 35">Under 35</option>
<option value=">35 - 44">35 - 44</option>
<option value=">45 - 54">45 - 54</option>
<option value=">55 - 59">55 - 59</option>
<option value=">60 - 64">60 - 64</option>
<option value=">65 - 69">65 - 69</option>
<option value=">70 - 74">70 - 74</option>
<option value=">75 - 79">75 - 79</option>
<option value="80 +">80 +</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="dependant" class="col-sm-7">• How many additional dependants will be covered?</label>
<div class="col-sm-10">
<select type="person" class="form-control form-control-sm" id="person" name="person">
<option value="0" selected disabled>Please Select</option>
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</select>
</div>
</div>
<input type="button" id="next" name="next" value="Next">
</form>
<div class="alli"> $0</div>
<script type="text/javascript">
$("#next").click(function update_pricing() {
//pricing data for pricing table
var pricing_data = {
single: {
"0" : [0, 0, 0],
"Under 35": [46.75, 124.25, 152.25],
">35 - 44": [51.75, 138.25, 168.50],
">45 - 54": [59.00, 152.25, 195.50],
">55 - 59": [63.25, 160.00, 209.00],
">60 - 64": [71.00, 170.50, 220.50],
">65 - 69": [58.50, 144.25, 187.00],
">70 - 74": [71.25, 187.50, 229.00],
">75 - 79": [77.50, 225.00, 303.75],
"80 +" : [97.25, 275.75, 366.00]
},
couple: {
"0" : [0, 0, 0],
"Under 35": [88.75, 236.75, 288.50],
">35 - 44": [99.00, 262.75, 320.75],
">45 - 54": [112.00, 288.50, 371.25],
">55 - 59": [120.25, 303.75, 397.50],
">60 - 64": [134.75, 323.75, 419.25],
">65 - 69": [111.25, 275.25, 355.50],
">70 - 74": [135.25, 356.50, 435.25],
">75 - 79": [147.75, 427.75, 577.00],
"80 +" : [184.50, 523.50, 696.00]
},
family: {
"0" : [0, 0, 0],
"Under 35": [116.50, 310.50, 379.00],
">35 - 44": [129.50, 345.25, 421.00],
">45 - 54": [147.25, 379.00, 488.25],
">55 - 59": [157.50, 399.00, 522.25],
">60 - 64": [177.00, 425.25, 551.50],
">65 - 69": [146.25, 361.25, 467.25],
">70 - 74": [177.50, 468.75, 572.50],
">75 - 79": [194.00, 562.25, 759.00],
"80 +" : [242.50, 688.50, 914.75]
}
}
var age_order = {
"0" : 0,
"Under 35": 1,
">35 - 44": 2,
">45 - 54": 3,
">55 - 59": 4,
">60 - 64": 5,
">65 - 69": 6,
">70 - 74": 7,
">75 - 79": 8,
"80 +" : 9
}
var age_fields = $('select[id^="dep_age_"], #age');
var family_size = parseInt($('#person').val());
var max_age = "0";
function do_update() {
var pricing_set;
//grab appropriate pricing set from pricing data
if (family_size == 0) {
pricing_set = pricing_data.single[max_age];
} else if (family_size === 1) {
pricing_set = pricing_data.couple[max_age];
} else if (family_size > 1) {
pricing_set = pricing_data.family[max_age];
}
var price_carrier = $('.alli'); //put price values here in pricing tables
//if appropriate pricing set is grabbed (not true when either one of age or family size not selected)
if (pricing_set) {
//put price values in all pricing tables
price_carrier.each(function (i, el) {
//if family members are more than 6, increase prices by 30%
if (family_size > 6) {
$(el).text('$' + (pricing_set[i] + pricing_set[i] * 0.3).toFixed(2));
} else {
$(el).text('$' + pricing_set[i].toFixed(2));
}
});
}
};
age_fields.each(function() {
if (age_order[$(this).val()] > age_order[max_age]) {
max_age = $(this).val();
}
});
do_update();
})
</script>
是否在所有網絡瀏覽器的工作? –
@FaheemFerozi https://developer.mozilla.org/en/docs/Web/API/Window/localStorage有一個支持的平臺列表。 – ADyson
是的,只要瀏覽器支持HTML5。本地和會話存儲是HTML5的一項功能。 –