2013-01-21 112 views
0

我已经制作了此表单,当用户从我的选择表单中选择“是”时,会显示某些选项。我无法得到我隐藏的div来显示,但我已经使用了控制台,发现至少将select改为yes确实会使我的if语句运行。我跑了一个测试和JQuery工作,但使用JQuery显示带有滑动和滑动的隐藏div

任何人都可以帮助我确定我要去哪里错了吗?

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

而CSS样式有

.hide { 
    display:none; 
} 
+0

请出示的例子在http://jsfiddle.net –

回答

3

此:

$(".hiddendiv1") 

不选择此元素:

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

这将是这样的:

$("#hiddendiv1") 

对于ID和.使用#,它可能有效吗?

FIDDLE

+0

完美的作品,非常感谢! – user1953507