|
簡化下注冊項目,干掉(隱藏)注冊密碼二次確認文本框。實際輸錯密碼的情況極少,萬一輸錯了還有密保郵箱不是,所以個人覺得可以省略哈
效果如圖:
QQ截圖20231207113956.jpg (78.31 KB, 下載次數: 46)
下載附件
2023-12-7 11:42 上傳
用JS隱藏掉確認框并同步密碼輸入即可,順便加了個顯示密碼的切換按鈕,不方向輸入是否正確時可以點擊顯示,人性化設計有木有
DEMO:https://cn.admxn.com/member.php?mod=register
食用方法:
將下方JS代碼拷貝到你當前模板的注冊頁面模板文件register.htm底部即可,默認路徑是\template\default\member\register.htm
<script>
// 查找所有type為password的input元素
const passwordInputs = document.querySelectorAll('input[type="password"]');
// 找到第二個密碼框所在的div并將其隱藏
let parentDiv = passwordInputs[1].parentNode;
while (parentDiv.tagName !== 'DIV') {
parentDiv = parentDiv.parentNode;
}
parentDiv.style.display = 'none';
// 監聽第一個密碼框的輸入事件
passwordInputs[0].addEventListener('input', function() {
// 將第一個密碼框的值同步到第二個密碼框
passwordInputs[1].value = passwordInputs[0].value;
});
// 顯示密碼
const buttonHtml = '<span id="showPasswordButton" class="fas fa-eye"></span>';
passwordInputs[0].insertAdjacentHTML('afterend', buttonHtml);
const showPasswordButton = document.getElementById('showPasswordButton');
let isPasswordVisible = false;
showPasswordButton.addEventListener('click', function() {
isPasswordVisible = !isPasswordVisible;
if (isPasswordVisible) {
// 切換為文本類型,密碼可見
passwordInputs[0].type = 'text';
showPasswordButton.classList.remove('fa-eye');
showPasswordButton.classList.add('fa-eye-slash');
} else {
// 切換回密碼類型,密碼隱藏
passwordInputs[0].type = 'password';
showPasswordButton.classList.remove('fa-eye-slash');
showPasswordButton.classList.add('fa-eye');
}
});
</script>
|
|