jsnb,
Вот мой код:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link type="text/css" rel="stylesheet" href="calculate.css"/>
<script type="text/javascript" src="jquery.js"></script>
<script src="calculate.js"></script>
</head>
<body>
<div id="calculator">
<div class="clr">
<input id="calcs" type="text"/>
</div>
<div class="clr">
<button class="button perevod">2</button>
<button class="button perevod">8</button>
<button class="button perevod">16</button>
<button class="button perevod">32</button>
</div>
<div class="clr">
<button class="button oneclick">+</button>
<button class="button oneclick">-</button>
<button class="button oneclick">/</button>
<button class="button oneclick">*</button>
</div>
<div class="clr">
<button class="button">1</button>
<button class="button">2</button>
<button class="button">3</button>
<button class="button">4</button>
</div>
<div class="clr">
<button class="button">5</button>
<button class="button">6</button>
<button class="button">7</button>
<button class="button">8</button>
</div>
<div class="clr">
<button class="button">9</button>
<button class="button">0</button>
<button id="calculate">=</button>
<button id="clear" class="button">c</button>
</div>
</div>
</body>
</html>
/**
* Created by Pashka on 29.04.14.
*/
$(document).ready(function(){
$('.button').click(function(){
$('#calcs').val($('#calcs').val() + $(this).html());
});
$('#clear').click(function(){
$('#calcs').val('');
});
$('#calculate').click(function(){
$('#calcs').val(eval($('#calcs').val()));
});
$('.perevod').click(function(){
var n = +$('#calcs').val();
$('#calcs').val(n.toString(2));
});
$('input').keypress(function(e) {
var verified = (e.which == 8 || e.which == undefined || e.which == 0) ? null : String.fromCharCode(e.which).match(/[^0-9]/);
if (verified) {
e.preventDefault();
}
});
});
Оно то работает, но как-то не совсем правильно, ведь 2 в двоичной системе будет 10, а не 10110?