我想在输入中只使用点(不是逗号)浮点值.
<input type="text" class="dot"> <br />
<input type="text" class="dot"> <br />
<input type="text" class="dot"> <br />
$('.dot').keydown(function(){
$(this).val($(this).val().toString().replace(/\,/g, '.'));
})
Run Code Online (Sandbox Code Playgroud)
这将逗号替换为点,但这不应该有> 1点和其他...这应该只接受[0-9]和.
如果我输入的值不同于其他[0-9]和.那么这个值应该删除 - ''.
我该怎么做?
我正在尝试使用一个简单的javascript函数,该函数旨在与单个数字的SELECT下拉列表一起使用,但现在我需要在访问者输入带小数点的值时使用它.即使我输入30或任何数字,我使用当前的javascript获得NaN.关于如何获得我的总数的任何建议?
JAVASCRIPT:
$(function () {
$('.DoPricing').change(function () {
var total = 0;
$('.DoPricing').each(function () {
total += parseInt($(this).val());
});
$('#TotalPrice').html('$' + total);
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<form action="myactionpage.php" method="POST">
<table>
<tr>
<td>How much will you be paying today?</td>
<td>$<input type="text" name="howmuch" id="howmuch" placeholder="0.00" class="DoPricing"></td>
</tr>
<tr>
<td><div class="totalbox">Total Amount Due Today: <strong><span id="TotalPrice">$0.00</span></strong></div>
</td>
</tr>
<tr><td><input type="submit" id="submit" name="submit" value="Submit Payment" class="submitbut" /></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)