gpt4 book ai didi

javaScript 无法转换字节

转载 作者:行者123 更新时间:2023-11-30 15:27:13 24 4
gpt4 key购买 nike

所以我遇到了一些问题。我试图在其中创建一个函数:人类用鼠标点击输入框并以字节为单位键入一些随机数,该数字应该转换并显示在其他两个框中,例如 MegaBytes 和 KiloBytes。所以我的问题是 Javascript 向我显示错误:

Cannot set property 'value' of null
at convert (script.js:7)
at HTMLInputElement.onkeyup

到目前为止,这是我的代码:

function convert(inputas)
{
var i;
if(inputas == "B")
{
i = document.getElementById("baitas").value / 1000;
document.getElementById("kiloBaitas").value = i;
}
else if(inputas == "KB")
{
i = document.getElementById("kiloBaitas").value * 1024;
document.getElementById("baitas").value = i.toFixed(2);
}
}

HTML代码:

<input type="text" id="baitas" onkeyup="convert('B')placeholder="Bits">
<input type="text" id="kilobaitas"
`onkeyup="convert('KB')"placeholder="Kilobits">
<input type="text" id="megabaitas" onkeyup="convert('MB')"
placeholder="Mbits">
<script src="script.js"></script>

最佳答案

将您的 javascript 与 html 进行比较时。 kilobaitis 元素拼写不一致。

关于javaScript 无法转换字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42775279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com