简体   繁体   中英

Sweet Alert is not taking two input area?

swal({
        title: "Log In to Continue",
        html: true,
        text: "Username: <input type='text'><br>Password: <input type='password'>",
        type:"input"
});

在此输入图像描述

 $(document).ready(function() {
  swal({
 title: "Error!",
  text: "Here's my error message!",
   type: "error",
  confirmButtonText: "Cool"
   });
  });

As Per your comment , I think You forgot to include jquery.js in your code try to include it in script and than try this code

<style>fieldset{

       display:none;

      }
<style>
$(document).ready(function() {
  swal({
 title: "Log In to Continue",
        html: true,
        text: "Username: <input type='text'><br>Password: <input type='password'>",
        type:"input"
   });
  });
 swal({
   title: 'Multiple inputs',
     html:
   '<input id="swal-input1" class="swal2-input" autofocus>' +
  '<input id="swal-input2" class="swal2-input">',
   preConfirm: function() {
   return new Promise(function(resolve) {
    if (result) {
      resolve([
        $('#swal-input1').val(),
        $('#swal-input2').val()
        ]);
      }
    });
   }
   }).then(function(result) {
 swal(JSON.stringify(result));
           })

type:"input" makes .sweet-alert input to display block and to enable your own inputs add Id/class name to the inputs and make them "display:block !important" using css.

Example code snippet

 $("#btnShowAlert").click(function() { sweetAlert({ title: "Log In to Continue", text: "Username: <input id='userName' type='text'><br>Password: <input id='password' type='password'>", html: true }); }); 
 .sweet-alert #userName, .sweet-alert #password { display: block !important; } 
 <link href="http://tristanedwards.me/u/SweetAlert/lib/sweet-alert.css" rel="stylesheet"/> <script src="http://tristanedwards.me/u/SweetAlert/lib/sweet-alert.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <button id="btnShowAlert"> Show Sweet Alert </button> 

I'm facing the same work around in R, part of the solution in a work around is doing this:

  sweetalert(title : "test message",
                text : "Username: <input type='text'><br>Password:",
                html : TRUE,
                type :  "input",
                confirmButtonColor : '#DD6B55',
                confirmButtonText : 'Yes, merge the files!',
                closeOnConfirm : FALSE)

I suppose. That would give you only 2 instead of 3 input fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM