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