/ / Calcolatrice Javascript non funzionante. - javascript, calcolatrice

Calcolatrice Javascript non funzionante. - javascript, calcolatrice

Ho creato questo calcolatore javascript poco fa. Ha funzionato perfettamente per me per anni, ma dopo essere tornato ad esso ho scoperto che semplicemente non funziona più.

Ecco il mio violino js ... http://jsfiddle.net/AdamMartin121/XXFXv/

Questo è il codice che ho usato. È molto lungo e probabilmente non necessario. Qualcuno sa innanzitutto perché non funziona, e in secondo luogo un modo più efficiente di farlo?

Javascript Code...

var display = document.getElementById("display");

document.addEventListener("DOMContentLoaded", init, false);


function init() {

var name = prompt("Enter your name", "");
if (name == null)
{
document.getElementById("head").innerHTML="Enter a name!";
}
else
{
document.getElementById("head").innerHTML= "<p>Welcome, " +name+ ". </p> <p2> This is a simple Javascript calculator. It is open source and was designed to help people to learn Javascript. <br> Feel free to copy and paste the code, and use it how you wish. </p>";
}
document.getElementById("calc").display.style.block;
}
function naught() {
var display= document.getElementById("display");
display.value+="0";
}
function one() {
var display= document.getElementById("display");
display.value+="1"
}
function two() {
var display= document.getElementById("display");
display.value+= "2";
}
function three() {
var display= document.getElementById("display");
display.value+="3";
}
function four() {
var display= document.getElementById("display");
display.value+="4";
}
function five() {
var display= document.getElementById("display");
display.value+="5";
}
function six() {
var display= document.getElementById("display");
display.value+="6";
}
function seven() {
var display= document.getElementById("display");
display.value+="7";
}
function eight() {
var display= document.getElementById("display");
display.value+="8";
}
function nine() {
var display= document.getElementById("display");
display.value+="9";
}
function add() {
var display= document.getElementById("display");
display.value+="+";
}
function take() {
var display= document.getElementById("display");
display.value+="-";
}
function times() {
var display= document.getElementById("display");
display.value+="*";
}
function divi() {
var display= document.getElementById("display");
display.value+="/";
}
function equal() {
var display= document.getElementById("display");
display.value= eval(display.value);
}

Grazie in anticipo.

risposte:

0 per risposta № 1

Questa linea:

document.getElementById("calc").display.style.block;

Dovrebbe essere questo (lo stile viene prima della visualizzazione):

document.getElementById("calc").style.display.block;

Inoltre, lo stai selezionando in JavaScript dall'ID calc, ma nella tua tabella HTML, gli hai dato il classe calc (<table class="calc">) invece, cambialo in ID (<table id="calc">) e voilà.


Lavoro jsFiddle qui.