简体   繁体   English

使用JQuery显示带有slideup和slidedown的隐藏div

[英]Using JQuery to display a hidden div with slideup and slidedown

I have made this form to let certain options appear when the user selects 'Yes' from my select form. 我制作了此表单,以便当用户从我的选择表单中选择“是”时出现某些选项。 I cannot get the div I have hidden to display at all, but I have used the Console and found that at least changing the select to yes does infact make my if statement run. 我根本无法隐藏隐藏的div,但是我使用了控制台,发现至少将select更改为yes确实会使我的if语句运行。 I've ran a test and JQuery is working, but 我进行了测试,JQuery正常运行,但是

Can anyone help me identify where I am going wrong? 谁能帮助我确定我要去哪里?

    <form method="post" action="quizcreatescript.php" name="quizcreateform" id="quizcreateform">

            <select name="choosemarks" id="choosemarks">
                       <option value="noweights">No</option>
                       <option value="yesweights">Yes</option>      
                </select>

<!-- >This div is hidden until the user selects yes to add own marks<-->        
<div class="hide" id="hiddendiv1"><!-- this select box will be hidden at first -->
<div class="input select">      
<input type="text" name="quizcorrectaward" id="quizcorrectaward"><br>   
<input type="text" name="quizincorrectaward" id="quizincorrectaward"><br>       
</div>  
</div>

<script type="text/javascript">         
$("#choosemarks").change(function(){ // when #choosemarks changes 
if ($(this).val() == "yesweights" ) { // if user selects to add own marks $(".hiddendiv1").slideDown("fast"); // if yes show the hidden div

                                    }  
else { $(".hiddendiv1").slideUp("fast");    //otherwise, hide the div again.

                                    }
                                });
</script>

                         <input type="submit" name="createthequiz" id="createquiz" value="Create Quiz">
                    </form>

And the CSS form has 而且CSS表单具有

.hide {
    display:none;
}

This: 这个:

$(".hiddendiv1")

does not select this element: 不选择此元素:

<div class="hide" id="hiddendiv1">

That would be this: 那是这样的:

$("#hiddendiv1")

Use # for ID and . #用作ID和. for classes, and it probably works ? 上课,这可能有效吗?

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM