From 4472382520a1e64ec4c63686001f66ce2612bf77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=BE=D0=B3=D0=BE=D1=80=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=98=D1=80=D0=B8=D0=BD=D0=B0?= Date: Thu, 15 Nov 2012 21:16:20 +0600 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=B74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4/Calculate.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 4/Calculator.html | 31 ++++++++++++++++++++++ 4/Style.css | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 4/Calculate.js create mode 100644 4/Calculator.html create mode 100644 4/Style.css diff --git a/4/Calculate.js b/4/Calculate.js new file mode 100644 index 0000000..fb989e2 --- /dev/null +++ b/4/Calculate.js @@ -0,0 +1,67 @@ +/*jslint plusplus: true, browser: true, devel: true */ + +document.getElementById('Form').onsubmit = function() { return false; }; + +var znak = false; // false, если до этого либо ничего не записывали, либо вводили число. true, если до этого был введен знак +var operand = 0; // сохраняет текущее значение +var s = ""; // последний введенный знак0 + +function createNumber(n) { + "use strict"; + var result = (document.getElementsByName("res")[0]).value; + + if (znak) { + result = n; + znak = false; + } else { + if (result === "0") {// если был ноль - меняем его на число + result = n; + } else {// иначе приписываем число + result = result + n; + } + } + (document.getElementsByName("res")[0]).value = result; + //alert("result " + result); +} + +function Operation(Op) { + "use strict"; + var result = (document.getElementsByName("res")[0]).value; + if (znak && s !== "=") {// если ввели, например, "++" + result = operand; + } else { + znak = true; + if (s === "+") { + operand = operand + parseFloat(result); + } + if (s === "-") { + operand = operand - parseFloat(result); + } + if (s === "/") { + operand = operand / parseFloat(result); + } + if (s === "*") { + operand = operand * parseFloat(result); + } + if (s === "=" || s === "") { + operand = parseFloat(result); + } + result = operand; + s = Op; + } + (document.getElementsByName("res")[0]).value = result; +} + +function point() { + "use strict"; + var result = (document.getElementsByName("res")[0]).value; + if (znak) { + result = "0."; + znak = false; + } else { + if (result.indexOf(".") === -1) { // если точки еще не было - дописываем. Иначе - игнорируемы + result = result + "."; + } + } + (document.getElementsByName("res")[0]).value = result; +} diff --git a/4/Calculator.html b/4/Calculator.html new file mode 100644 index 0000000..f93ee5e --- /dev/null +++ b/4/Calculator.html @@ -0,0 +1,31 @@ + + + + + Калькулятор + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/4/Style.css b/4/Style.css new file mode 100644 index 0000000..411bb66 --- /dev/null +++ b/4/Style.css @@ -0,0 +1,66 @@ +form { + width: 300px; + height: 420px; + position: absolute; + left: 50%; + margin-left: -150px; + top: 50px; + border: 5px solid #D0ECF4; + background: -webkit-gradient(linear, 0 0, 0 100%, from(#D0ECF4), to(#D0ECF4), color-stop(0.5, #5BC9E1)); + +} + +input { + height: 90px; + width: 290px; + font-size: 150%; + text-align: right; +} +button { + background: -webkit-gradient(linear, 0 0, 0 100%, from(#D0ECF4), to(#D0ECF4), color-stop(0.5, #5BC9E1)); + height: 80px; + position: absolute; + font-size: 150%; + width: 75px; +} +button[name*="0"] { + bottom: 0; + width: 75px; +} +button[name*="1"] { + bottom: 80px; + width: 75px; +} +button[name*="2"] { + bottom: 160px; + width: 75px; +} +button[name*="3"] { + bottom: 240px; + width: 75px; +} +button[name*="Ноль"] { + width: 150px; +} +button[name*="Точка"],[name*="Три"],[name*="Шесть"],[name*="Девять"] { + left: 150px; +} +button[name*="Два"],[name*="Пять"] ,[name*="Восемь"]{ + left: 75px; +} +button[name*="Равно"],[name*="Плюс"],[name*="Минус"],[name*="Умножить"],[name*="Разделить"] { + right: 0; + height: 64px; +} +button[name*="Плюс"] { + bottom: 64px; +} +button[name*="Минус"] { + bottom: 128px; +} +button[name*="Умножить"] { + bottom: 192px; +} +button[name*="Разделить"] { + bottom: 256px; +} \ No newline at end of file From b4c412ac26a181dfde1939c6df3d3e8775095ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=BE=D0=B3=D0=BE=D1=80=D1=8C=D0=B5?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=98=D1=80=D0=B8=D0=BD=D0=B0?= Date: Sun, 2 Dec 2012 22:47:28 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D1=81=20jQuery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (и заменила onclick) --- 4/Calculate.js | 40 +++++++++++++++++++++++++++++----------- 4/Calculator.html | 37 +++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/4/Calculate.js b/4/Calculate.js index fb989e2..36c0610 100644 --- a/4/Calculate.js +++ b/4/Calculate.js @@ -1,14 +1,13 @@ /*jslint plusplus: true, browser: true, devel: true */ -document.getElementById('Form').onsubmit = function() { return false; }; - var znak = false; // false, если до этого либо ничего не записывали, либо вводили число. true, если до этого был введен знак var operand = 0; // сохраняет текущее значение var s = ""; // последний введенный знак0 -function createNumber(n) { +function createNumber() { "use strict"; - var result = (document.getElementsByName("res")[0]).value; + var n = this.value, + result = ($(".result")).val(); if (znak) { result = n; @@ -20,13 +19,13 @@ function createNumber(n) { result = result + n; } } - (document.getElementsByName("res")[0]).value = result; - //alert("result " + result); + ($(".result")).val(result); } -function Operation(Op) { +function Operation() { "use strict"; - var result = (document.getElementsByName("res")[0]).value; + var Op = this.value, + result = ($(".result")).val(); if (znak && s !== "=") {// если ввели, например, "++" result = operand; } else { @@ -49,12 +48,12 @@ function Operation(Op) { result = operand; s = Op; } - (document.getElementsByName("res")[0]).value = result; + ($(".result")).val(result); } function point() { "use strict"; - var result = (document.getElementsByName("res")[0]).value; + var result = ($(".result")).val(); if (znak) { result = "0."; znak = false; @@ -63,5 +62,24 @@ function point() { result = result + "."; } } - (document.getElementsByName("res")[0]).value = result; + ($(".result")).val(result); } + +$(document).ready(function () { + "use strict"; + var $button_number = $(".button_type_number"), + $button_znak = $(".button_type_znak"), + $button_point = $(".button_type_point"); + + $('#Form').submit(function () { "use strict"; return false; }); + + $button_number.each(function (index, element) { + $(element).click(createNumber); + }); + $button_znak.each(function (index, element) { + $(element).click(Operation); + }); + $button_point.each(function (index, element) { + $(element).click(point); + }); +}); \ No newline at end of file diff --git a/4/Calculator.html b/4/Calculator.html index f93ee5e..50a482d 100644 --- a/4/Calculator.html +++ b/4/Calculator.html @@ -4,28 +4,29 @@ Калькулятор + +
- - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + +
- \ No newline at end of file