首页 > 网站 > WEB开发 > 正文

文件大小的计算,是关于bytes、K、M、G等的计算

2024-04-27 13:57:35
字体:
来源:转载
供稿:网友

<!-- 把如下代码加入<body>区域中 -->
<form name="bandwidth">
  <p><input type="text" name="original" size="20" value=1024> <select size="1" name="units">
    <option value="Bytes">Bytes</option>
    <option value="Kb">Kb</option>
    <option value="Mb">Mb</option>
    <option value="Gb">Gb</option>
  </select> <input type="button" value="详细计算" name="B1" onClick="calculate()"></p>
</form>

<script>
var bytevalue=0
function calculate(){
var invalue=document.bandwidth.original.value
var selectunit=document.bandwidth.units.options[document.bandwidth.units.selectedIndex].value
if (selectunit=="Bytes")
bytevalue=invalue
else if (selectunit=="Kb")
bytevalue=invalue*1024
else if (selectunit=="Mb")
bytevalue=invalue*1024*1024
else if (selectunit=="Gb")
bytevalue=invalue*1024*1024*1024

alert (invalue+" "+selectunit+" 等于:/n/n- "+bytevalue+" Bytes/n- "+Math.round(bytevalue/1024)+" Kb/n- "+Math.round(bytevalue/1024/1024)+" Mb/n- "+Math.round(bytevalue/1024/1024/1024)+" Gb/n")
}

</script>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表