Окончательный эффект, как показано на рисунке 2. Существует ошибка: результат щелчка % после того, как целое число является правильным. Если % нажимается после десятичного десятичного, результат будет неправильным! Остальные нормальные, пожалуйста, дайте мне несколько советов: значение ввода имеет тип строки. Как правильно обработать часть, если на рисунке-1 ниже в JS? ?
Рисунок-1
Рисунок-2
HTML -код выглядит следующим образом
<body> <div id = "calculator"> <div> <pan> простой калькулятор </span> <pan> @walker </span> </div> <div id = "shuru"> <!-входной панель экрана-> <div> <input type = "text" id = "ecreenname" name = "screenname"> </div> </div> <div ID = "name"! type = "кнопка" id = "7" onclick = "jsq (this.id)" value = "7"> <input type = "кнопка" id = "8" onclick = "jsq (this.id)" value = "8"> <input type = "кнопка" id = "9" onclick = "jsq (this.id)" value = "9"> <input type = "indol" "in vice =" back = "back =" back = "in vice =" incue = "in vice ed -ed1". value = "Back"> <input type = "button" id = "c" onclick = "clearnum ()" value = "c" style = "inclight: 0px"> <!-вторая строка-> <input type = "id =" 4 "Onclick =" jsq (this.id) "value =" 4 "> <input =" id "5" onClic <input type = "кнопка" id = "6" onclick = "jsq (this.id)" value = "6"> <input type = "кнопка" id = "*" onclick = "jsq (this.id)" value = "x"> <input type = "кнопка" id = "/" Onclick = "jsq (this.Id)" value = "/" style = "mArgin-right: 0Px-jsq (this.Id)"/"/" "/" "-0P-right" type = "кнопка" id = "1" onclick = "jsq (this.id)" value = "1"> <input type = "кнопка" id = "2" onclick = "jsq (this.id)" value = "2"> <input type = "кнопка" id = "3" onclick = "jsq (this.id)" value = "3"> <input type = "id Id Id"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+". onclick = "jsq (this.id)" value = "+"> <input type = "button" id = "-" onclick = "jsq (this.id)" value = "-" style = "margin-right: 0px"> <!-Четвертая строка-> <input type = "кнопка" id = "0" onclick = "jsq (this.id)" value = "value ="> "vint" in vint "in inte" in inture = "vint". onclick = "jsq (this.id)" value = "00"> <input type = "кнопка" id = ".". " onclick="jsq(this.id)" value="."> <input type="button" id="%" onclick="jsq(this.id)" value="%"> <input type="button" id="eva" onclick="eva()" value="=" style="margin-right:0px"> </div> <div> <span>Welcome to JavaScript calculator</span> <span> <a href = "#" target = "_ blank"> обратная связь </a> </span> </div> </div> </body>
Код CSS выглядит следующим образом:
<style> /*Базовый сброс* /*{margin: 0; Заполнение: 0; Распределение коробки: пограничная коробка; шрифт: 14px arial, sans-serif;} html {height: 100%; фоновый цвет: LightsLategrey;}#Calculator {Margin: 15px Auto; Ширина: 330px; Высота: 400px; Граница: 1PX Solid Lightgray; Фоно-цвета: Darkgrey; Padding: 15px;}/*logo*/. Logo {height: 20px;}. Logo .name {float: left; Линия-высота: 30px;}. Logo .verson {float: right; Line-Height: 30px;}/*Screen*/#shuru {margin-top: 15px;}. Screen {margin-top: 5px; Ширина: 300px; Высота: 40px; Текст-альбом: верно; Право накладки: 10px; Font-Size: 20px;}#Keys {Border: 1px Solid Lightgray; Высота: 223px; маржинальная версия: 25px; Padding: 8px;}#Keys .last {Margin-Right: 0px;}. Cooler {margin-top: 20px; Высота: 20px;}. Cooler .link {float: right;}#keys .buttons {float: left; Ширина: 42px; Высота: 36px; Текст-альбом: Центр; Фоно-цвета: Lightgray; Полевая: 0 17px 20px 0;} </style>Код JavaScript выглядит следующим образом:
<script> var num = 0; // Определите данные первой входной функции jsq (num) {// Получить текущий ввод if (num == "%") {document.getElementById ('Screenname'). Value = math.round (document.getElementById ('Screenname'). Value)/100; } else {document.getElementById ('Screenname'). value += document.getElementById (num) .value; }} function eva () {// Вычислять входной результат document.getElementById ("Screenname"). Value = eval (document.getElementById ("Screenname"). Value); } function clearNum () {// clear 0 document.getElementById ("Screenname"). value = null; document.getElementbyId ("Screenname"). Focus (); } function tuige () {// backspace var arr = document.getElementbyid ("screenname"); arr.value = arr.value.substring (0, arr.value.length - 1); } </script>Приведенная выше статья JavaScript реализует простой эффект калькулятора [рекомендуется] - это весь контент, которым я делюсь с вами. Я надеюсь, что вы можете дать вам ссылку, и я надеюсь, что вы сможете поддержать Wulin.com больше.