admin管理员组文章数量:1402935
Input Grams(g):
<input type="text" name="grams" id="grams"><br>
<br>
<button type="button" onclick="kilo()">Kilogram</button>
<p id="convert"></p>
<script type="text/javascript">
function kilo(){
}
Input Grams(g):
<input type="text" name="grams" id="grams"><br>
<br>
<button type="button" onclick="kilo()">Kilogram</button>
<p id="convert"></p>
<script type="text/javascript">
function kilo(){
}
Share
Improve this question
edited Mar 27, 2017 at 4:05
gyre
16.8k4 gold badges40 silver badges47 bronze badges
asked Mar 27, 2017 at 3:45
Cheska MontemayorCheska Montemayor
31 silver badge3 bronze badges
7
- 2 multiply by 1024 – Jaromanda X Commented Mar 27, 2017 at 3:45
- 4 no, wait ... 1000 – Jaromanda X Commented Mar 27, 2017 at 3:46
- @JaromandaX Seriously? I think you confused with Kilobytes, is it. – Shubham Khatri Commented Mar 27, 2017 at 3:47
- Divide by 1000. If you convert grams to kilograms you divide by 1000 (eg, 15g = 0.015Kg). If you convert kilograms to grams you multiply by 1000 (eg, 15Kg = 15,000g). – Gerardo Furtado Commented Mar 27, 2017 at 3:49
- @JaromandaX i mean in my question is if the user input a grams by clicking the button of kilograms the amount will appear.. – Cheska Montemayor Commented Mar 27, 2017 at 3:54
2 Answers
Reset to default 5
Input Grams(g): <input type="text" name="grams" id="grams">
<br>
Results: <p id="convert"></p>
<button onclick="kilo()">Kilogram</button>
<script type="text/javascript">
function kilo() {
document.getElementById('convert').innerHTML =
(document.getElementById('grams').value/1000 + "kg");
}
</script>
var ratio = 1000;
function kilo(grams) {
return grams / ratio ;
}
本文标签: htmlConvert grams to kilo grams in javascript by clicking the button of kilogramsStack Overflow
版权声明:本文标题:html - Convert grams to kilo grams in javascript by clicking the button of kilograms - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744285640a2598864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论