我试着找一种方法,知道我的输入电子邮件是否有一些价值,它在。
我试过这个代码:
var empty = true;
//get value from my input type email
$('input[type="email"]').each(function() {
//check out if I have some values its in
if ($(this).val()!="") {
// if my input is empty then its should return this
//redefined my var with false
empty = false;
//return a console saying that my input is empty
return console.log("empty yep");
}
});
我该怎么做?
我尝试创建一个登录名,当我在输入密码上放置某项内容时,我的javascript检测到我的电子邮件中是否有什么内容,如果我没有任何东西,那么就不允许在我的系统中继续进行进程登录,而不需要将电子邮件放在系统中。
什么主意?
发布于 2019-12-01 04:39:52
在HTML的head部分添加jquery库
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>然后在HTML代码中添加一个输入标记,如下所示
<form name="form" action="" method="" onsubmit="validate()">
<input type="email" name="email" id="email" value="" required>
</form>然后,在jquery中,请粘贴以下代码
if($('#email').val() == '') {
alert('please provide the email').
event.preventDefault();
return false;
}注意:您甚至可以验证电子邮件id。
发布于 2019-12-01 04:32:03
根据我的理解,您需要验证电子邮件以输入下一个密码输入框。
因此,我已使密码输入禁用,除非有东西被输入到电子邮件输入框。
使用email.nextElementSibling.setAttribute('disabled',true);使密码字段禁用。
然后,如果您开始输入电子邮件,那么密码字段将被启用。
const email = document.querySelector('input[type="email"]');
checkEmailValidation = () => {
if(email.value){
email.nextElementSibling.removeAttribute("disabled");
} else {
email.nextElementSibling.setAttribute('disabled',true);
}
}
email.addEventListener('input', checkEmailValidation);
checkEmailValidation();<input type="email" placeholder="Type email here">
<input type="password" placeholder="Type password here">
https://stackoverflow.com/questions/59122391
复制相似问题