简体   繁体   English

我如何知道输入电子邮件是否对 jquery 有价值?

[英]how I can know if a input e-mail has value in with jquery?

I try find a way of know if my input email has some values its in.我尝试找到一种方法来了解我的输入电子邮件是否包含某些值。

I tried this code:我试过这个代码:

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

what do I trying do?我想做什么?

I try create a login that when I put something over the input password my javascript detect if I have something in email if I do not have nothing then dont allow continue with the process login in my system without before put the email我尝试创建一个登录名,当我在输入密码上放一些东西时,我的 javascript 检测我的电子邮件中是否有东西,如果我什么都没有,那么在没有放入电子邮件之前,不允许在我的系统中继续登录过程

some idea?一些想法?

Based on my understanding, You need to validate the email to enter the next password input box.根据我的理解,您需要验证电子邮件才能进入下一个密码输入框。

So I have made the password input disabled unless something is entered into email input box.因此,除非在电子邮件输入框中输入某些内容,否则我已禁用密码输入。

Using email.nextElementSibling.setAttribute('disabled',true);使用email.nextElementSibling.setAttribute('disabled',true); made the password field as disabled.将密码字段设为禁用。

Then if you start entering into email then the password field will get enabled.然后,如果您开始输入电子邮件,那么密码字段将被启用。

 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">

Add jquery library in head section of HTML在 HTML 的 head 部分添加 jquery 库

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

then add an input tag in HTML code as below然后在 HTML 代码中添加一个 input 标签,如下所示

<form name="form" action="" method="" onsubmit="validate()">
    <input type="email" name="email" id="email" value="" required>
</form>

then in jquery please paste the below code然后在jquery中请粘贴以下代码

if($('#email').val() == '') {
    alert('please provide the email').
    event.preventDefault();
    return false;
}

Note: you can even validate the email id.注意:您甚至可以验证电子邮件 ID。

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

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