简体   繁体   中英

Jquery alternate sweet alert

I want to run the program so that if the result returned is str4 or str2, the sweet alert will throw up an "error" instead of a "success" icon but I have no idea how.

Here is the code:

$( document ).ready(function() {

   $( "#w2" ).click(function() {
    swal({
        title: result(),
        icon: "success",
        button: "OK",
    });
   });


   function result() {

    var str = $("#w1").val().toLowerCase();
    var str2 = "This is not a cafe";
    var str3 = "This cafe does have a plug source";
    var str4 = "This cafe does not have a plug source";

    if (str== "cafe express" || str=="cafeexpress") {
        return str3;
    } else if ( str=="jungle cafe" || str=="junglecafe") {
        return str4;
    } else {
        return str2;
    }

   }

});
$( document ).ready(function() {

   $( "#w2" ).click(function() {
    var res = result();
    swal({
        title: res[0],
        icon: res[1],
        button: "OK",
    });
   });


   function result() {

    var str = $("#w1").val().toLowerCase();
    var str2 = "This is not a cafe";
    var str3 = "This cafe does have a plug source";
    var str4 = "This cafe does not have a plug source";

    if (str== "cafe express" || str=="cafeexpress") {
        return [str3, "success"];
    } else if ( str=="jungle cafe" || str=="junglecafe") {
        return [str4, "error"];
    } else {
        return [str2, "error"];
    }

   }

});

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