所以我想要 3 个可以写入的输入字段,库存、平均时间和小时数,我已经看到了一些与此相关的答案,但我仍然不确定,因为我对此很陌生。我对 jquery 不了解,所以这不是一个选择,谢谢。
<h3>Work out how much you could be saving!<h3>
<button type="button" class="calculate">Calculate</button>
<script type="text/javascript">
// Do the Javscript here!
function calc (inventories, hours, wage) {
return (inventories * hours) * wage;
}
$('.calculate').click(function(){
// Put variables here
console.log (calc ( , , ));
// Call the caclulation function
// Output function to text here..
});
</script>
最佳答案
添加输入,
<input type="number" id="inventories" />
其他人也一样
通过以下方式获取这些字段的内容:
$("#inventories").val();
你的计算函数将类似于:
var inventories = $("#inventories").val();
var wage = $("#wage").val();
var hours = $("#hours").val();
calc(inventories,hours,wage);
关于javascript - 获取输入字段的值,并用它们进行一些计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29987189/