编辑: 这是一个 JSfiddle
Edit2:错误在这一行:<input type="button" value="totalbandwidthresult" onclick="javascript:totalbandwidth();">
试图让一个按钮执行计算。所需的变量如下,以及 HTML 其中
我在点击时收到错误消息:Uncaught TypeError: object is not a function index.html:71
onclick
这是我的 Javascript
function totalbandwidth() {
var fps=Number(document.calculator.fps.value);
var bitrate=Number(document.calculator.bitrate.value);
var numberofcameras = Number(document.calculator.numberofcameras.value);
var encoding = document.calculator.encoding.value;
if (encoding = "mjpeg")
{
storage = bitrate*fps;
}
else
{
storage = bitrate;
}
totalbandwidth = (numberofcameras * storage) / 1000;
document.calculator.totalbandwidthresult.value = totalbandwidth;
}
的HTML:
<form name="calculator" class="formtable">
<div class="formrow"><label for="rcname">RC Name</label> <input type="text" name="rcname"></div>
<div class="formrow"><label for="fps">FPS</label> <input type="text" name="fps"> </div>
<div class="formrow"><label for="bitrate">Bitrate</label> <input type="text" name="bitrate"> </div>
<div class="formrow"><label for="numberofcameras">Number of Cameras</label> <input type="text" name="numberofcameras"> </div>
<div class="formrow"><label for="encoding">Encoding</label> <select name="encoding" id="encodingoptions">
<option value="h264">H.264</option>
<option value="mjpeg">MJPEG</option>
<option value="mpeg4">MPEG4</option>
</select></div>
Total Storage: <input type="text" name="totalstorage">
Total Bandwidth: <input type="text" name="totalbandwidth">
<input type="button" value="totalbandwidthresult" onclick="javascript:totalbandwidth();">
基本上 - 我在 JS 中使用的语法似乎有问题 - 但我不确定。