如何在 keyup 事件而不是在提交时显示输出以及输入字段内的值?
我试过只读<input id="result" name="totalamount" value="" readonly/>
但它不工作。有人可以吗?
这是完整的代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
$('#myForm').submit(function (event) {
event.preventDefault();
var actualprice = Number($("#actualprice").val().trim());
var discount = Number($("#discount").val().trim());
var shipping = Number($("#shipping").val().trim());
var discountRate = (100 - discount) / 100;
var result = (actualprice * discountRate) + shipping;
$("#result").html("Result :" + result.toFixed(2));
});
</script>
<form id="myForm">
<input id="actualprice" type="number" placeholder="Actual Price">
<input id="discount" type="number" placeholder="Discount">
<input id="shipping" type="number" placeholder="Shipping">
<input id="result" name="totalamount" value="" readonly/>
<h3 id="result"></h3>
<input type="submit" value="Submit">
</form>