简体   繁体   中英

Sweet Alert input with condition

How can I put up a condition for the string entered in input field like if userName equals to 'xyz' then swal("welcome!") else swal("better next time")? So far I have my code given below.

> swal({
         title: "Proceeding...",
         content: {
                  element: "input",
                  attributes: {
                      placeholder: "Type up your userName",
                      type: "userName",
                  },              
                },
       });

You could:

swal("Write something here:", {
  content: "input",
})
.then((value) => {
  if (value === 'xyz') {
    swal(`Username: ${value}`);
  }
});

Refer to: https://sweetalert.js.org/guides/#using-dom-nodes-as-content

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