我有一个飞镖脚本从两个<input>
元素获取值并比较它们以检查它们是否相等。但是出于某种奇怪的原因,其中一个<input>
元素的值始终为""
(即使我已经在里面引入了文本)两个输入的代码都是相同的,并且其中一个输入的代码是完全相同的。飞镖没有得到输入值
这些是输入:
Contraseña:<input maxlength="30" name="psswd" type="password"><br>
Confirmar contraseña:<input maxlength="30" name="psswd-confirm" type="password"><br>
而这是DART代码来检查,如果它们的值是相等的(这就是所谓的当用户点击一个按钮)
InputElement passwordInput = querySelector('[name="psswd"]');
InputElement psswdConfirmInput = querySelector('[name="psswd-confirm"]');
if (passwordInput.value != psswdConfirmInput.value) {
showBlock(querySelector("#signup-psswd-error1"));
return;
}
的showBlock()
函数只改变元素的风格,使其display: block
,我不认为有问题。
EDIT 整个表格中的代码如下:
<form name="signup" id="form-signup" action="http://localhost:8080" method="post">
<span id="signup-email-error1">Esta dirección de correo electrónico ya ha sido registrada.</span>
<span id="signup-email-error2">Las dos direcciones de correo electrónico no coinciden.</span>
<span id="signup-psswd-error1">Las dos contraseñas no coinciden.</span>
<span id="signup-empty-error1">Debes completar todos los campos.</span>
Correo electrónico:<input maxlength="30" name="email" type="email" value=""><br>
Confirmar correo:<input maxlength="30" name="confirm-email" type="email" value=""><br>
Contraseña:<input maxlength="30" name="psswd" type="password"><br>
Confirmar contraseña:<input maxlength="30" name="psswd-confirm" type="password"><br>
Nombre y apellidos:<input maxlength="30" name="name" type="text" value=""><br>
<button id="signup-submit">Crear cuenta</button>
</form>
的<span>
元素是默认隐藏,仅显示在错误的错误消息。
编辑 HTML传递时没有任何错误,也没有警告w3c验证程序的验证,所以可能错误不存在。飞镖事件监听器功能相关的错误代码如下:
signupSubmit.onClick.listen((e) {
e.preventDefault();
for (int i = 0; i < signupForm.children.length; i++) { //AUTOMATIC HIDING
if (signupForm.children[i] is SpanElement) {
hide(signupForm.children[i]);
}
}
for (int i = 0; i < signupForm.children.length; i++) { //CHECK FOR EMPTY FIELDS
Element element = signupForm.children[i];
if (element is InputElement) {
if (element.value == "") {
showBlock(querySelector("#signup-empty-error1"));
return;
}
}
}
InputElement emailInput = querySelector('[name="email"]');
InputElement emailConfirmInput = querySelector('[name="confirm-email"]');
if (emailInput.value != emailConfirmInput.value) {
showBlock(querySelector("#signup-email-error2"));
return;
}
InputElement passwordInput = querySelector('[name="psswd"]');
InputElement psswdConfirmInput = querySelector('[name="psswd-confirm"]');
hide(passwordInput);
hide(psswdConfirmInput);
print('passwordInput: ${passwordInput.value}');
print('confirm: ${psswdConfirmInput.value}');
if (passwordInput.value != psswdConfirmInput.value) {
showBlock(querySelector("#signup-psswd-error1"));
print('psswd different');
return;
}
var req = new HttpRequest();
req.onReadyStateChange.listen((e) {
if (req.readyState == HttpRequest.DONE) {
print(req.responseText);
if (req.responseText == "regComplete") {
hide(overlay);
Element newel1 = new HeadingElement.h1();
newel1.text = "¡Gracias por registrarte!";
Element newel2 = new HeadingElement.h2();
newel2.text = "Se ha enviado un correo electrónico a la dirección proporcionada.";
Element newel3 = new HeadingElement.h2();
newel3.text = "Haz click en el enlace recibido para verificar la dirección y confirmar el registro.";
Element newel4 = new HeadingElement.h4();
newel4.text = "Del equipo de CampL con ♡";
querySelector("#welcome")
..children.clear()
..children.add(newel1)
..children.add(newel2)
..children.add(newel3)
..children.add(newel4);
} else if (req.responseText == "mailTaken") {
showBlock(querySelector("#signup-email-error1"));
}
}
});
req.open('POST', signupForm.action);
req.send(JSON.encode(serializeForm(signupForm)));
print('Data submitted!');
});
这就是当我看到即使两个密码相同时错误消息出现,但passwordInput的值始终为''“'(因此在输入”rr“到输入时的代码输出是''passwordInput:“”confirm:rr“') – dieortin
我怀疑在输入密码之前你的标记中有一些错误,这会使字段变得很奇怪。 –
我用整个表单的代码更新了我的问题。 – dieortin