我正在尝试为我的网站创建一个注册页面,但我不知道如何在密码和确认密码不匹配后阻止用户单击提交。
如果两个密码不匹配,我有一个“警告”功能。
HTML:
<input type="password" name="password" value="" id="password" placeholder="Password">
<input type="password" name="confirm_password" id="confirm_password" placeholder="Confirm Password" onkeyup='check();'/>
span id='message'></span>
JS:
var check = function() {
if (document.getElementById('password').value ==
document.getElementById('confirm_password').value) {
document.getElementById('message').style.color = 'green';
document.getElementById('message').innerHTML = 'Passwords are matching';
} else {
document.getElementById('message').style.color = 'red';
document.getElementById('message').innerHTML = 'Passwords does not match' ;
}
}
我当时在考虑布尔函数,但是我不知道如何在内部调用它以及如何取消提交。
答案 0 :(得分:1)
向您的suspend fun executeTraderOperation(...): Any {
...
suspend fun execOperation() = traderMonitorRestClient.executeTraderOperation(
traderOperation.toString().toLowerCase(), base.trim(), quote.trim(), sender, key)
if (isCustomtHandle) {
return runOperationWithoutHandle(::execOperation)
} else {
return runOperationWithDefaultHandle(::execOperation)
}
在Submit事件上调用<form onsubmit="validate()">
将阻止表单实际提交。
preventDefault
答案 1 :(得分:0)
您可以在密码不匹配时禁用按钮
//IF I AM CONNECTED WITH ANDROID THEN MIRROR THE ANDROID TRACK TO WEB
//CLONE STREAM
var androidStream = new MediaStream(androidPeer.getRemoteStreams()[0]);
//CLONE EACH TRACK AND ADD TO THE WEB PEER
androidStream.getTracks().forEach(function (track) {
webPeer.addTrack(track.clone(), androidStream);
});
答案 2 :(得分:0)
在您的JS中,为什么不将值放入变量中?没必要,但是可以使JS更清洁
在该函数ID中执行
var password = document.getElementById('password').value
var confrm_password = document.getElementById('confirm_password').value
const button = document.getElementById('button') (Or however you want to target the button, up to you)
和
button.disabled = (password === confirm_password))