如果我创建了一个订单,并希望允许用户使用表单类型为"number“的基于数字的输入来选择产品数量,您将使用什么事件来触发总成本的计算?我尝试过oninput,但它只是输出错误“未捕获TypeError:对象没有方法'oninput'”
例如,下面的代码:
<label>Number of products:</label> <input name="product" id="product" type="number" /> Total Value: $ <span id="result"></span>
和计算:
jQuery(document).ready(function(){
jQuery('#product').oninput(function(){
jQuery('#result').text(jQuery('#product').val() * 25.99);
});
});
http://jsfiddle.net/7BDwP/806/
发布于 2012-08-01 00:03:46
您需要使用change
事件。
$(document).ready(function(){
$('#product').change(function(){
$('#result').text($(this).val() * 25.99);
});
});
此外,您可能希望为输入字段添加一个最小值:
<input name="shares" id="product" type="number" min=0 />
https://stackoverflow.com/questions/11744296
复制相似问题