我想运行该程序,以便如果返回的结果是str4或str2,那么甜蜜警报会引发一个"错误"而不是成功"图标,但我不知道如何。
以下是代码:
$( 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;
}
}
});
答案 0 :(得分:0)
$( 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"];
}
}
});