Hallo Leute.
ich habe 2 markante Fehler die mir gerade aufgefallen sind.
1. wenn man / rechnet, springt der weg (Buchstaben und Zahlen werden doppelt geschrieben??!!)
2. man kann den Rechner ohne Probleme mit den Keyboard nehmen, aber nicht mit wie es eigentlich sein soll, mit der Maus ('undefined')
Hier ist mal ein JSFiddle:
Edit fiddle - JSFiddle
Und hier der Code (ohne CSS):
HTML:
JQuery:
Wisst ihr woran es liegt?
€: Sorry hab (falls vorhanden) keine Spoiler gefunden :/
ich habe 2 markante Fehler die mir gerade aufgefallen sind.
1. wenn man / rechnet, springt der weg (Buchstaben und Zahlen werden doppelt geschrieben??!!)
2. man kann den Rechner ohne Probleme mit den Keyboard nehmen, aber nicht mit wie es eigentlich sein soll, mit der Maus ('undefined')
Hier ist mal ein JSFiddle:
Edit fiddle - JSFiddle
Und hier der Code (ohne CSS):
HTML:
HTML:
<body>
<div id="calculator">
<input id="display" class="input" />
<div id="numbers">
<button>7</button>
<button>8</button>
<button>9</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="colspan">0</button>
<button>.</button>
</div>
<div id="operators">
<button>/</button>
<button>←</button>
<button>*</button>
<button>C</button>
<div id="operator" style="float:left;width:37px;">
<button>-</button>
<button>+</button>
</div>
</div>
<button class="rowspan">=</button>
</div>
</body>
JQuery:
Code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$("#numbers").children("button").each(function(){
$(this).attr("id","no"+$(this).text());
$(this).attr("class","Show");
$(this).attr("value",""+$(this).text());
$(this).attr("type","button");
});
$("#operators").children("button").each(function(){
$(this).attr("id","op"+$(this).text());
$(this).attr("class","operators operand");
$(this).attr("value",""+$(this).text());
$(this).attr("type","button");
});
$("#operator").children("button").each(function(){
$(this).attr("id","op"+$(this).text());
$(this).attr("class","operators operand");
$(this).attr("value",""+$(this).text());
$(this).attr("type","button");
});
$('.rowspan').attr("id","Calculate");
$('.rowspan').attr("type", "button");
$('.rowspan').attr("class", "equal");
$('.colspan').attr("class", "zerokey");
$(function(){
//Calc Object with display,clear,doCal methods
var Calc={
display:function(v){
$("#display").val(v);
},
clear:function(){
$("#display").val(" ");
},
doCal:function(val){
var result="";
var dtemp=$("#display").val();
if(dtemp=="0"){
this.clear();
result=val;
}else if(val=="c"){
this.clear();
}else if(val=="="){
result=eval(dtemp);
}else{
result=dtemp+val;
}
this.display(result);
}
}
//Keyboard key press event.
$("body").keypress(function(e){
Calc.doCal(String.fromCharCode(e.which));
});
//calc UI click events
$('#calculator').click(function(e){
e.preventDefault();
Calc.doCal(this.value);
});
});
});
</script>
Wisst ihr woran es liegt?
€: Sorry hab (falls vorhanden) keine Spoiler gefunden :/