0
我是jQuery的新手,现在我有一个表单根据输入字段中键入的数字提供报价。现在它只是拉入并除以2.我想从另一个领域拉另一个数字来改变我的等式中可以整除的数字。所以我们假设我有一个叫做乘数的字段,我想把它放到我有什么格式呢? 0.50就是我想做一个变量,从另一个输入字段拉。jQuery从输入字段中提取值
$(function() {
// the minimum required value to be entered.
// in this case PayPal takes $0.35 from a $1
// donation, hence we ask for at least $1.35
var multiplier = $("#multiplier").val();
var minimum_value = 1.35;
// cache elements that are used at least twice
var $amount = $("#input_amount"),
$brandMatch = $("#autocomplete-ajax"),
$msg = $("#msg"),
$commission = $("#site_commission_box");
// attach handler to input keydown event
$amount.keyup(function(e) {
if (e.which == 13) {
return;
}
var amount = parseFloat($amount.val()),
//brandMatch = 0.6;
commission = amount * multiplier;
if (isNaN(commission) || isNaN(amount)) {
$msg.hide();
$commission.hide();
return;
}
if (amount <= minimum_value) {
$commission.hide();
$msg
.text("Please fill in a higher amount")
.fadeIn();
} else {
$msg.hide();
$commission
.fadeIn()
.find("span")
//.text((amount - commission).toFixed(2));
.text((amount - commission).toFixed(2));
}
});
});
所以我只是试图实现你的建议,并希望确保我将它添加到正确的位置,因为它不适合我。在我的输入字段中,我添加了“乘数”顶部我加了'var multiplier = $(“#multiplier”)。val(); '在等式中我增加了'佣金=金额*倍数;' – MatrixHyperLoop
您是否在新的输入元素中添加了新的ID并保持旧的输入字段“金额”相同? –
实际上,当硬编码value =“2”时它正在工作,但我希望它在输入时读取值,因此我可以更改字段中的内容以查看报价 – MatrixHyperLoop