if语句给出相同的输出,如果输入框中的值没有显示正确的消息,则IF的第一部分将起作用

问题描述 投票:0回答:1

在两种情况下,函数给出的输出都是相同的?

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",
    }, );
  }
}
javascript cordova geofencing
1个回答
0
投票

即不需要其他您也可以使用!==代替!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"
  });
}
© www.soinside.com 2019 - 2024. All rights reserved.