0
    <script type="text/javascript">

    $(document).ready(function(){

    $("#click").click(function () {
    $("#info").slideToggle('slow');
    });

    });

    </script>

这是html代码

        <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>

我有这个用于切换效果的代码。但是,切换不会保持关闭状态,我希望切换保持关闭,直到有人单击按钮以释放切换。有任何想法吗?代码写得好吗?

4

3 回答 3

0

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

示例: http: //jsbin.com/oxuqus/2/http://jsfiddle.net/kB2fc/

CSS:

#info {
  display: none;
} 

JS:

$(document).ready(function(){

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

});
于 2013-06-26T12:26:06.463 回答
0

只需将其添加到您的 CSS

#info {
   display : none;
}
于 2013-06-26T12:16:52.730 回答
0

工作示例

(jsFiddle)

解释

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


解决方案

将以下内容添加到您的CSS:

#info
{
    display:none;
}

笔记

你没有关闭你的inputspan元素!添加结束标签:

<input type="radio" name="response" value="I'll be there with bells on!" id="response">I'll be there with bells on!
</input>
</span>
于 2013-06-26T12:16:53.297 回答