Javascript 获取输入字段的值,并对其进行计算

Javascript 获取输入字段的值,并对其进行计算,javascript,html,user-input,Javascript,Html,User Input,所以我想要3个输入字段,他们可以写,库存,av时间和小时,我已经看到了一些答案,与此相关,但我仍然不确定,因为我是新手。我不知道jquery,所以这不是一个选项,谢谢 <h3>Work out how much you could be saving!<h3> <button type="button" class="calculate">Calculate</button> <script type="text/javascript"

所以我想要3个输入字段,他们可以写,库存,av时间和小时,我已经看到了一些答案,与此相关,但我仍然不确定,因为我是新手。我不知道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>

<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>
添加输入

<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" />
您的计算函数类似于:

<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>
var inventories = $("#inventories").val();
var wage = $("#wage").val();
var hours = $("#hours").val();
calc(inventories,hours,wage);

你自己做过什么研究?搜索html javascript表单让我明白了这一点:我认为值得一看。您可能会找到其他有用的链接。在您的问题中,您说您不知道jquery,因此这不是一个选项,但您的代码示例中有jquery。您当前是否正在使用jquery?