http://puu.sh/3r1jk.pngJavascript .keyup()問題
我有那段代碼,最近實現了滑塊。當滑塊移動時,它會根據我的需要更改win%。但是如果我在輸入中輸入60%,它會更新乘數和利潤。我希望它通過滑塊更新乘數和利潤。
代碼更新輸入:
$(document).ready(functon() {
function updateValues() {
// Grab all the value just incase they're needed.
var chance = $('#chance').val();
var bet = $('#bet').val();
var pay = $('#pay').val();
var profit = $('#profit').val();
// Calculate the new payout.
pay = Math.floor((9900/(parseFloat(chance) + 0.5)) * 100)/10000;
// Calculate the new profit.
profit = bet * pay - bet;
profit = profit.toFixed(6);
$('#chance').val(chance);
$('#bet').val(bet);
$('#pay').val(pay);
$('#profit').val(profit);
}
parseFloat($('#chance').keyup(updateValues));
parseFloat($('#bet').keyup(updateValues));
parseFloat($('#pay').keyup(updateValues));
parseFloat($('#profit').keyup(updateValues));
});
代碼通過滑塊來更新獲勝%:
examples.push({
range: [.01, 98],
start: 49,
handles: 1,
connect: "lower",
serialization: {
to: [$(".exVal")]
}
});
HTML:
<div class="form-box">
<label for="bet">Bet Amount</label>
<input type="text" name="bet" id="bet" class="text" placeholder="amount" />
</div>
<div class="form-box">
<label for="pay">Multiplier</label>
<input type="text" name="pay" id="pay" class="text" placeholder="Payout - 2x Default" />
</div>
<div class="form-box last">
<label for="pay">Profit</label>
<input type="text" name="profit" id="profit" class="text" placeholder="Profit" />
</div>
<div class="clearfix"></div>
<div class="form-box">
<label for="chance">Win Chance (%)</label>
<input type="text" name="chance" id="chance" class="text exVal" value="50" placeholder="Win % - 50.5% Default" />
</div>
<p>Slide to choose win chance or enter it in the input!</p>
<div class="noUiSlider" id="chance" style="margin: 25px 100px 10px 220px; colour:#00aec8;"></div>
爲什麼不將其更新?
您可以將圖像中的代碼添加到您的問題中嗎?你還可以添加你的HTML? – Joe
編輯OP。 HTML:http://puu.sh/3r1Mm.png – user2534566
由於滑塊只是將值放入'#chance.exVal',但不會觸發'keyup'事件 - 您必須手動調用'updateValues' 。如果您可以向我們展示您使用的滑塊代碼,我們可以幫助您解決這個問題。 – Bergi