栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在不重新加载页面的情况下检查表单中的确认密码字段

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在不重新加载页面的情况下检查表单中的确认密码字段

我们将研究实现这一目标的两种方法。使用和不使用jQuery。

1.使用jQuery

您需要将添加KEYUP功能,您的密码和确认密码字段。原因是即使

password
字段更改,也应检查文本相等性。感谢@kdjernigan指出

这样,当您在字段中键入内容时,您将知道密码是否相同:

$('#password, #/confirm/i_password').on('keyup', function () {  if ($('#password').val() == $('#/confirm/i_password').val()) {    $('#message').html('Matching').css('color', 'green');  } else     $('#message').html('Not Matching').css('color', 'red');});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><label>password :  <input name="password" id="password" type="password" /></label><br><label>confirm password:  <input type="password" name="/confirm/i_password" id="/confirm/i_password" />  <span id='message'></span></label>

这是小提琴:http :
//jsfiddle.net/aelor/F6sEv/325/

2.不使用jQuery

我们将在两个字段上使用javascript
的onkeyup事件来达到相同的效果。

var check = function() {  if (document.getElementById('password').value ==    document.getElementById('/confirm/i_password').value) {    document.getElementById('message').style.color = 'green';    document.getElementById('message').innerHTML = 'matching';  } else {    document.getElementById('message').style.color = 'red';    document.getElementById('message').innerHTML = 'not matching';  }}<label>password :  <input name="password" id="password" type="password" onkeyup='check();' /></label><br><label>confirm password:  <input type="password" name="/confirm/i_password" id="/confirm/i_password"  onkeyup='check();' />   <span id='message'></span></label>

这是小提琴:http :
//jsfiddle.net/aelor/F6sEv/324/



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/393470.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号