9527 發表於 2023-12-7 11:51:50

不删代码干掉注册密码二次确认文本框

<br /><br />简化下注册项目,干掉(隐藏)注册密码二次确认文本框。实际输错密码的情况极少,万一输错了还有密保邮箱不是,所以个人觉得可以省略哈<br />效果如图:<br /><img title="QQ截图20231207113956.jpg" id="aimg_26790" aid="26790" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/202312/07/114208q9n9yv2tgsspt9yt.jpg" src="https://www.dismall.com/data/attachment/forum/202312/07/114208q9n9yv2tgsspt9yt.jpg" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" /><br />用JS隐藏掉确认框并同步密码输入即可,顺便加了个显示密码的切换按钮,不方向输入是否正确时可以点击显示,人性化设计有木有<br />DEMO:https://cn.admxn.com/member.php?mod=register<br /><br />食用方法:<br />将下方JS代码拷贝到你当前模板的注册页面模板文件register.htm底部即可,默认路径是\template\<font style="background-color:yellow">default</font>\member\register.htm<br /><br />&lt;script&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; // 查找所有type为password的input元素<br />&nbsp; &nbsp; &nbsp; &nbsp; const passwordInputs = document.querySelectorAll('input');<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // 找到第二个密码框所在的div并将其隐藏<br />&nbsp; &nbsp; &nbsp; &nbsp; let parentDiv = passwordInputs.parentNode;<br />&nbsp; &nbsp; &nbsp; &nbsp; while (parentDiv.tagName !== 'DIV') {<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;parentDiv = parentDiv.parentNode;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; parentDiv.style.display = 'none';<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // 监听第一个密码框的输入事件<br />&nbsp; &nbsp; &nbsp; &nbsp; passwordInputs.addEventListener('input', function() {<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;// 将第一个密码框的值同步到第二个密码框<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;passwordInputs.value = passwordInputs.value;<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // 显示密码<br />&nbsp; &nbsp; &nbsp; &nbsp; const buttonHtml = '&lt;span id=&quot;showPasswordButton&quot; class=&quot;fas fa-eye&quot;&gt;&lt;/span&gt;';<br />&nbsp; &nbsp; &nbsp; &nbsp; passwordInputs.insertAdjacentHTML('afterend', buttonHtml);<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; const showPasswordButton = document.getElementById('showPasswordButton');<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; let isPasswordVisible = false;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; showPasswordButton.addEventListener('click', function() {<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;isPasswordVisible = !isPasswordVisible;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if (isPasswordVisible) {<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 切换为文本类型,密码可见<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;passwordInputs.type = 'text';<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;showPasswordButton.classList.remove('fa-eye');<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;showPasswordButton.classList.add('fa-eye-slash');<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;} else {<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 切换回密码类型,密码隐藏<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;passwordInputs.type = 'password';<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;showPasswordButton.classList.remove('fa-eye-slash');<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;showPasswordButton.classList.add('fa-eye');<br />&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;}<br />&nbsp; &nbsp; &nbsp; &nbsp; });<br />&lt;/script&gt;<br /><br /><br /><br />密码<em>, </em>passwordInputs<em>, </em>显示<em>, </em>注册<em>, </em>隐藏

9527 發表於 2023-12-8 09:15:04

<img title="微信图片_20231208091129.jpg" id="aimg_26809" aid="26809" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/202312/08/091456b30sm7kha1ka4t3w.jpg" src="https://www.dismall.com/data/attachment/forum/202312/08/091456b30sm7kha1ka4t3w.jpg" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" /><img title="微信图片_20231208091438.jpg" id="aimg_26808" aid="26808" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/202312/08/091456gcxznbpjhbqdzi8q.jpg" src="https://www.dismall.com/data/attachment/forum/202312/08/091456gcxznbpjhbqdzi8q.jpg" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" /><br />

海哥 發表於 2023-12-8 13:21:50

回帖留名

ysx24 發表於 2023-12-10 11:46:30

好东西,不错

文強 發表於 2023-12-10 12:18:52

这个的确不错

9527 發表於 2023-12-12 17:15:51

// 选择器改为查找id为registerform内的所有type为password的input元素,这样更严谨,不然默认模板会选中头部的登录框<br />const passwordInputs = document.querySelectorAll('#registerform input');<br />

E.Kun 發表於 2023-12-28 19:08:25

这个好~!

s77 發表於 2023-12-31 01:50:38

学习一下

小巅峰 發表於 2024-7-8 22:56:06

666666666666666666666

小巅峰 發表於 2024-7-11 12:31:34

66666666666666
頁: [1]
查看完整版本: 不删代码干掉注册密码二次确认文本框