html - .setAttribute 没有正确隐藏。 HTML/CSS

标签 html css

 function displayEditProfileStudent() {
        document,getElementById('editstudentprofile').setAttribute('class', 'unhide');
        document.getElementById('profile_viewStudent').setAttribute('class', 'hide');
        document.getElementById('ViewStudent').setAttribute('class', 'unhide');
    }
    function displayProfileViewStudent() {
        document,getElementById('editstudentprofile').setAttribute('class', 'hide');
        document.getElementById('profile_viewStudent').setAttribute('class', 'unhide');
        document.getElementById('ViewStudent').setAttribute('class', 'unhide');
    }

<div id="ViewStudent" class="hide">
            <a href="#ViewProfileStudent" class="student_profile_view col-sm-1" onclick= "displayProfileViewStudent()" >View Profile</a>
            <a href="#EditProfileStudent" class="student_profile_edit col-sm-1" onclick="displayEditProfileStudent()">Edit Profile</a>
            <form id="editstudentprofile" class="hide">
                <h4>Edit Profile</h4>
                <label class="col-sm-3">Major:</label>
                <input class="major_input col-sm-5" name="studentmajor" type="text" placeholder="Enter your Major">
                <br/>
                <label class="col-sm-3">Cumulative GPA:</label>
                <input class="GPA_input col-sm-1" name="studentGPA" type="text" placeholder="GPA">
                <br/>
                <label class="col-sm-3">Expected Graduation Date:</label>
                <input class="graduation_input col-sm-2" name="studentgraduationdate" type="text" placeholder="MM/DD/YYYY">
                <br/>
                <label class="col-sm-3">Have you served as a TA before?</label><br/>
                <input class="previousTA_input" name="previousTA" type="radio"> Yes<br/>
                <input class="previousTA_input" name="previousTA" type="radio"> No<br/>
                <a href="#EditProfileStudent" class="editaccount_btn btn btn-default" >Update Profile</a>
            </form>
            <div id="profile_viewStudent" class="hide">
                <h4>Profile</h4>
            </div>
        </div>

当我单击查看个人资料/编辑个人资料的链接时,它不会显示或隐藏另一个,我看到的是同一个屏幕。感谢您提供任何帮助,我尝试浏览其他帖子,据我所知,目前还没有任何帮助。

此外,这是隐藏类的 CSS。

div.hide {
display: none;}

form.hide {
display: none;}

最佳答案

你可以试试

document.getElementById('editstudentprofile').classList.add('unhide');
document.getElementById('editstudentprofile').classList.remove('hide');

此外,在您的示例中,您使用 , 而不是 . 在两行 document 之后。

关于html - .setAttribute 没有正确隐藏。 HTML/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58826153/

相关文章:

javascript - Firefox 扩展打开一个 HTML 选项页面

javascript - 每天限制 Facebook 礼物请求

css - 在html5中更改背景颜色

internet-explorer - Css 在 IE 兼容性 View 中不工作

html - 修复了底部导航栏下拉菜单在较小屏幕上下拉到导航栏的问题

html - 如何停止在移动设备上溢出边界?

javascript - gauge.js - 相对 URL 不起作用,但绝对 URL 在 Django 1.10 中起作用

block - 将 block 级 <span> 元素放在 <p> 元素中

javascript - 仅针对指向某个网站的出站链接的独特样式

javascript - 单击按钮后使 HTML 元素可编辑并保存在数据库中