需要 $post 选择框的文本,而不是它们的值。
HTML:
<select name="one" id="one">
<option value="0">Select *</option>
<option value="3000">Plan A</option>
<option value="6000">Plan B</option>
<option value="9000">Plan C</option>
</select>
<br />
<select name="two" id="two">
<option>Please choose from above</option>
</select>
<div id="total"></div>
JS:
// arrays instead of comma separated list and added base key
var data = {
"0": ["Please choose from above"],
"3000": ["saad_0", "Coffee_465", "Coke_984"],
"6000": ["saad_0", "Coffee_465", "Coke_984"],
"9000": ["saad_0", "Chips_123", "Cookies_987"]
}
$("#one").change(function () {
var first = $(this),
second = $("#two"),
key = first.val(),
// instead of the original switch code
vals = data[key] == undefined ? data.base : data[key],
html = [];
// create insert html before adding
$.each(vals, function (i, val) {
var v = val.split('_');
html.push('<option value="' + v[1] + '">' + v[0] + '</option>')
});
// no need to empty the element before adding the new content
second.html(html.join());
});
$("#one,#two").change(function () {
var val1 = parseInt($('#one').val()) || 0,
val2 = parseInt($('#two').val()) || 0;
$('#total').text(val1 + val2)
})
我正在使用什么:
$message .= "<br>One : " . $_POST['one'];
$message .= "<br>Two : " . $_POST['two'];
在电子邮件结果中,我得到了我不想要的值。因为值仅用于计算。
有人告诉我将我的 post 方法与 jquery 绑定,我对此一无所知。
演示:jsfiddle 链接