小编bri*_*124的帖子

如何使用 vanilla JavaScript 编写我在 JQuery 中编写的切换函数?

昨天试图让这段代码使用 JavaScript 工作几个小时,因为我真的很想尽可能地了解基础知识,但最终放弃并用 JQuery 编写它。想要一些关于如何用 vanilla JS 编写的建议。我只是想用一个按钮来显示一个隐藏的“div”,所以我觉得它应该很简单,我只是忽略了一些东西:

查询:

$('document').ready(function() {
    $('.aboutBtn').click(function() {
        $('#more-brian').toggleClass('hide');
    });
})
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="row">

            <div class="card col-sm-6">
            <h5 class="card-title">Brian Davis</h5>
              <img class="card-img-top" src="../soccer-travel-site/img/brian-davis.jpg" alt="Brian Davis photo">
              <div class="card-body">
                <p class="card-text">Brian is the founder of AO Adventures and an original host of the BarrelProof Podcast.<button type="button" class="btn btn-danger aboutBtn">More About Brian</button></p>
              </div>
            <div id="more-brian" class="hide">
                <p id="brian-para">Brian is a husband and father who is very passionate about soccer. He has been to over 50 U.S. Men's …
Run Code Online (Sandbox Code Playgroud)

javascript jquery toggle show-hide

3
推荐指数
1
解决办法
7697
查看次数

标签 统计

javascript ×1

jquery ×1

show-hide ×1

toggle ×1