Методы JavaScript для пользовательского ввода: подсказки и формы

Вот несколько методов в JavaScript, которые предлагают пользователю ввести данные:

  1. Использование функции prompt():

    let userInput = prompt("Please enter your input:");
  2. Создание пользовательской формы ввода HTML и доступ к ее значению с помощью JavaScript:

    <input type="text" id="userInput">
    <button onclick="getUserInput()">Submit</button>
    <script>
     function getUserInput() {
       let userInput = document.getElementById("userInput").value;
       // Use the userInput variable as needed
     }
    </script>
  3. Использование библиотеки или платформы, например пользовательского интерфейса jQuery:

    $("#dialog").dialog({
     modal: true,
     buttons: {
       Ok: function() {
         let userInput = $("#inputField").val();
         // Use the userInput variable as needed
         $(this).dialog("close");
       },
     },
    });
  4. Использование библиотеки модальных диалогов, например SweetAlert:

    Swal.fire({
     title: "Enter your input:",
     input: "text",
     showCancelButton: true,
     confirmButtonText: "Submit",
    }).then((result) => {
     if (result.isConfirmed) {
       let userInput = result.value;
       // Use the userInput variable as needed
     }
    });