需要$发布选择框的文本,而不是它们的值。
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'];
在电子邮件结果中我得到了我不想要的价值观。因为只需要计算值。
有人告诉我用jquery绑定我的post方法,我不知道它。
答案 0 :(得分:0)
$("#yourdropdownid option:selected").text();