javascript - 试图让下一个和上一个按钮出现在注册表单的不同时间
问题描述
您好,我正在尝试为我的网站制作注册表单,我正在做下一个和上一个来浏览我的网站,我的下一个和上一个工作良好,但我希望在第一个问题时隐藏上一个按钮和当我回答最后一个问题时显示的注册标志。
这是我的 JS
var nameRegistration = document.querySelector('.name-
registration');
var emailRegistration = document.querySelector('.email-
registration');
var industriesRegistration = document.querySelector('.industries-
registration');
var birthRegistration = document.querySelector('.birth-
registration');
var passwordRegistration = document.querySelector('.password-registration');
var nextContainer = document.querySelector('#forward');
var backContainer = document.querySelector('#back');
var registerContainer = document.querySelector('#register-btn-container');
if (nameRegistration.style.display === 'none ') {
backContainer.style.display = 'block'
}
if (passwordRegistration.style.display === 'block') {
registerContainer.style.display = 'block'
}
解决方案
您可以通过多种方式实现这一点,例如,让计数器知道您在流程的哪一部分,并在每个“部分”更改时保持递增和递减,并据此采取行动。
checkSection 编辑您需要的选项/字段。
let activeSection = 0;
const checkSection = position => {
//if not in the start, hide start section/button/option
if(position == 0) {
document.getElementById('id').style.display = 'none';
document.getElementById('otherid').style.display = 'block';
}
else {
document.getElementById('id').style.display = 'none';
document.getElementById('otherid').style.display = 'block';
}
}
//and control where you are with listeners to the clicks
document.getElementById('linkmoveup').addEventListener('click',function(e){
//don't follow link
e.preventDefault();
//lets assume this is for the next point, increment position counter
activeSection++;
//recheck for what is active
checkSection(activeSection);
});
推荐阅读
- vue.js - 是否可以通过 Mustache 语法 {{}} 传递 Vue 组件?
- linux - os.system 运行路径包含空格的 chrome 应用程序。Mac 和 Linux 的结果不同
- django - 使用一种 POST 方法保存多个表单。(姜戈)
- python - 使用 F 字符串显示浮点数
- javascript - 禁用特定页面的机车滚动
- python - 如果dict值等于数字,如何打印带有字典中项目的值?
- oracle - ORA-04092: 无法在触发器中回滚
- python - 显示 Django 图像:视图和模型需要冲突的静态根目录
- c# - Bogus - Faker 选择随机的自定义类型
- angular - 抛出新错误('找不到本地“打字稿”包。')