在两种情况下,函数给出的输出都是相同的?
function showToast() {
if (document.getElementById("latitude").innerHTML == "") {
window.plugins.toast.showWithOptions({
message: "Geofence perimeter has been correctly set. \n \n Hence you may now proceed with Geofence Activation",
duration: "short",
position: "top",
}, );
} else if (!document.getElementById("latitude".innerHTML == "")) {
window.plugins.toast.showWithOptions({
message: "Geofence perimeter cannot be set due to missing configuration \n \n Kindly update all fields accordingly",
duration: "short",
position: "top",
}, );
}
}
即不需要其他您也可以使用!==代替!something ==“”
请使用三元。注意?
和冒号:
function showToast() {
const empty = document.getElementById("latitude").innerHTML === ""; // are you sure it IS empty?
const message = empty ?
"Geofence perimeter has been correctly set. \n \n Hence you may now proceed with Geofence Activation" :
"Geofence perimeter cannot be set due to missing configuration \n \n Kindly update all fields accordingly"
window.plugins.toast.showWithOptions({
message: message,
duration: "short",
position: "top"
});
}