Javascript 切换不保持关闭状态,我必须单击按钮以关闭切换 $(文档).ready(函数(){ $(“#单击”)。单击(函数(){ $(“#info”).slideToggle('slow'); }); });

Javascript 切换不保持关闭状态,我必须单击按钮以关闭切换 $(文档).ready(函数(){ $(“#单击”)。单击(函数(){ $(“#info”).slideToggle('slow'); }); });,javascript,jquery,html,css,toggle,Javascript,Jquery,Html,Css,Toggle,这是html代码 只需将其添加到CSS中 <h4 class="rsvpTitle"> <a href="#" id="click" class= "blockExpand"> <span class="arrow"></span>RSVP</a> </h4> <div id="info" class="expandCont

这是html代码



只需将其添加到CSS中

        <h4 class="rsvpTitle">


        <a href="#" id="click" class= "blockExpand"> <span class="arrow"></span>RSVP</a>
        </h4>           
        <div id="info" class="expandContent">  

            <form id="formmail method="post" action="form_handler.php">

                <label class="response" for="response">Will you be joining us?</label><br>
                <span style="margin-left:121px;">   
                <input type="radio" name="response" value="I'll be there with bells on!" id="response">I'll be there with bells on!</span>
                <br>
(jsFiddle)

解释 该元素在文档
load
事件中不隐藏。必须使用
display:none隐藏它,以确保它在没有用户交互的情况下不可见


解决方案 将以下内容添加到您的
CSS

#info {
   display : none;
}
注 您没有关闭
输入
span
元素!添加结束标记:

#info
{
    display:none;
}
我会准时赶到的!

u必须添加显示:无;将#info和e.preventDefault()添加到js

示例: 或

CSS:

JS:


按钮在哪里?我想他是指你在我给你的css上错过的主播
#info
{
    display:none;
}
<input type="radio" name="response" value="I'll be there with bells on!" id="response">I'll be there with bells on!
</input>
</span>
#info {
  display: none;
} 
$(document).ready(function(){

  $("#click").on("click", function(e) {
    $("#info").slideToggle('slow');
    e.preventDefault();
  });

});