[英]Javascript decimal to hexadecimal
I'm very new to programming and am trying to write an application for a decimal to hexadecimal converter.我对编程很陌生,正在尝试编写一个十进制到十六进制转换器的应用程序。 When you type a number into a number box (in base 10) and you see the base-16 equivalent appearing as the value in the box change.当您在数字框(以 10 为基数)中键入一个数字时,您会看到以 16 为基数的等效项随着框中值的变化而出现。 I cannot figure out how to make my program run.我不知道如何让我的程序运行。 Any suggestions would be greatly appreciated!任何建议将不胜感激! HTML: HTML:
Base Ten:
<input type="number" id="base10" onkeydown="convertBase10to16()">
<br>Base Sixteen:
<input id='base16'>
Javascript: Javascript:
var base10 =
document.getElementById("base10");
var base16 =
document.getElementById("base16");
var convertBase10to16() = {function () {
if (id("base10").value !== '')
{id("base16").value = parseInt(id("base10").value,10).toString(16);}
};
https://jsfiddle.net/8yvjyy4b/3/ https://jsfiddle.net/8yvjyy4b/3/
Your code have several syntax errors.您的代码有几个语法错误。 Here is what it should look like这是它应该是什么样子
var base10 = document.getElementById("base10");
var base16 = document.getElementById("base16");
base10.addEventListener("blur", function() {
var num = Number(this.value);
base16.value = num.toString(16);
});
https://jsfiddle.net/8yvjyy4b/4/ https://jsfiddle.net/8yvjyy4b/4/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.