简体   繁体   English

为什么我的代码没有在 javascript 中显示确认弹出窗口?

[英]Why my code doesn´t display a confirm popup in javascript?

I have the following function in a script linked to a form in html.我在链接到 html 表单的脚本中具有以下功能。 When everything is ok the navigator should create 3 cookies and display a confirm popup but it doesn´t display the confirm popup but it creates the cookies.当一切正常时,导航器应该创建 3 个 cookie 并显示一个确认弹出窗口,但它不显示确认弹出窗口,但它创建了 cookie。 I have tried in firefox, I didn´t do it in chrome because it does extrange things with cookies so i prefered firefox我曾在 Firefox 中尝试过,但我没有在 chrome 中进行过,因为它确实可以用 cookie 来扩展事物,所以我更喜欢 Firefox

I'm new to stackoverflow so any advice will be appreciated我是 stackoverflow 的新手,所以任何建议都将不胜感激

PD: some parts of the code are in Spanish (valor=value nombre=name contraseña=password) PD:代码的某些部分是西班牙语(valor=value nombre=name contraseña=password)

function checkForm() {
  var emailValue = document.getElementById("email").value;
  var nombreValue = document.getElementById("nombre").value;
  var passValue = document.getElementById("pass1").value;
  if(comprobarCookie("email", emailValue)==false){
  if (CheckPass()) {//si las contraseñas coinciden, creamos la cuenta
    createCookie("email", emailValue);
    createCookie("nombre", nombreValue);
    createCookie("pass", passValue);
    var confirm=confirm("!Tu cuenta ha sido creada con éxito!")
    if (confirm==true) {
      location.replace("https://www.w3schools.com")
    } else {
      txt = "No has creado la cuenta";
    }
  } else {
    alert("las contraseñas no coinciden")
  }
  }else{
    alert("Ya existe una cuenta con ese email")
  }
}

Looks like you're using the reserved word confirm as your variable to test.看起来您正在使用保留字confirm作为要测试的变量。 Try replacing:尝试更换:

 var confirm=confirm("!Tu cuenta ha sido creada con éxito!")
if (confirm==true) {
  location.replace("https://www.w3schools.com")
} else {
  txt = "No has creado la cuenta";
}

with

var user_clicked = confirm("!Tu cuenta ha sido creada con éxito!");
if (user_clicked === true) {
  location.replace("https://www.w3schools.com");
} else {
  txt = "No has creado la cuenta";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM