如果语句给出相同的输出,如果输入框中有值,则 IF 的第一部分有效,它不会显示正确的消息

if statement is giving the same output the first part of the IF works if there's value in the input box it doesn't show the correct message

该函数在两种情况下给出相同的输出,我做错了什么?

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",
    }, );
  }
}

else中的if不需要 你也可以使用 !== 而不是 !something == ""

最后,如果 document.getElementById("latitude") 是一个输入字段,您需要测试 .value , 不是 innerHTML

请使用三元。注意 ? 和冒号 :

function showToast() {
  const empty = document.getElementById("latitude").value.trim() === "" // to be 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"
  });
}