Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   вывести значение кнопки в текстовое поле (https://javascript.ru/forum/misc/48363-vyvesti-znachenie-knopki-v-tekstovoe-pole.html)

рони 16.04.2016 14:50

Цитата:

Сообщение от Gigles
Возможно ли это сделать без JQuery?

да
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>"Экранная Клавиатура"</title>
  </head>
  <body>
    <input type="text" id="result" name="result" class="result" /><br />
    <button type="button" class="button_style" value="1" name="one">1</button>
    <button type="button" class="button_style" value="2" name="two">2</button>
  <script>
window.addEventListener("DOMContentLoaded", function() {
    var but = document.querySelectorAll(".button_style"),
        res = document.querySelector(".result");
    [].forEach.call(but, function(item) {
        item.addEventListener("click", function() {
            res.value += item.value
        })
    })
});
  </script>
  </body>
</html>


Часовой пояс GMT +3, время: 03:06.