Jquery slideup/slidedown不';我不能再工作了

Jquery slideup/slidedown不';我不能再工作了,jquery,slidedown,slideup,Jquery,Slidedown,Slideup,我试图编写一个代码,显示基于选择框的包含表单元素的div框。我认为解释这个问题最简单的方法就是举个例子 如果你看这把小提琴。请尝试以下操作: 首先选择选项1,搜索表单1出现..正确。 选择选项3,搜索表1和2出现,这也是正确的 但现在,当您再次选择选项1时。应显示searchform 1时未显示任何表单 说到jQuery,我是个新手,所以如果我的脚本不够漂亮,你知道原因 我的jQuery: $(document).ready(function() { $("#select").change(f

我试图编写一个代码,显示基于选择框的包含表单元素的div框。我认为解释这个问题最简单的方法就是举个例子

如果你看这把小提琴。请尝试以下操作:

首先选择选项1,搜索表单1出现..正确。 选择选项3,搜索表1和2出现,这也是正确的 但现在,当您再次选择选项1时。应显示searchform 1时未显示任何表单

说到jQuery,我是个新手,所以如果我的脚本不够漂亮,你知道原因

我的jQuery:

$(document).ready(function() {
$("#select").change(function() {

    var val = $(this).val();

    if (val == "value1" || val == "value2") { //check if value 1 or 2 are selected

        $("#search2").slideDown("fast"); //Slide Down Effect
        $("#search1").slideUp("fast");

    } else {

        $("#search1").slideUp("fast"); //Slide Down Effect
        $("#search1").slideUp("fast");

    }

    $("#select").change(function() {

        var val = $(this).val();

        if (val == "value3" || val == "value4" || val == "value5") { // check if value 3, 4 or 5 are selected

            $("#search1").slideDown("fast"); //Slide Down Effect
            $("#search2").slideDown("fast");

        } else {

            $("#search1").slideUp("fast"); //Slide Down Effect
            $("#search2").slideUp("fast");

        }
    });
});
}));​

HTML:


伊克·佐克:
(选择)
选择1
选择2
选择3
选择4
备选案文5
奥普莱丁

邮政编码
名称
有什么想法吗?

试试这个JSFIDLE:

根据我看到的,您只需要添加另一个else if语句(检查值3,4,5)

当再次选择
(选项)
时,我添加了另一个else if向上滑动

以下是更新后的Javascript:

$(document).ready(function() {

    //On Select Change...
    $("#select").change(function() {

        //Get Current Value
        var val = $(this).val();

        //If the value is the 1st or 2nd dropdown...
        if (val == "value1" || val == "value2") {
            //Slide down the second search form and slide up the first
            $("#search2").slideDown("fast"); //Slide Down Effect
            $("#search1").slideUp("fast");
        } 
        //If the value is the 3rd, 4th, or 5th dropdown...
        else if(val == "value3" || val == "value4" || val == "value5") {
            //Slide down both the forms
            $("#search1").slideDown("fast"); //Slide Down Effect
            $("#search2").slideDown("fast");
        } 
        //If the value is nothing (choice is selected)...
        else{
            //Slide up both forms
            $("#search1").slideUp("fast");
            $("#search2").slideUp("fast");
        }
    });
});​
我删除了你原来的
else
语句,因为它不需要。

试试这个JSFIDLE:

根据我看到的,您只需要添加另一个else if语句(检查值3,4,5)

当再次选择
(选项)
时,我添加了另一个else if向上滑动

以下是更新后的Javascript:

$(document).ready(function() {

    //On Select Change...
    $("#select").change(function() {

        //Get Current Value
        var val = $(this).val();

        //If the value is the 1st or 2nd dropdown...
        if (val == "value1" || val == "value2") {
            //Slide down the second search form and slide up the first
            $("#search2").slideDown("fast"); //Slide Down Effect
            $("#search1").slideUp("fast");
        } 
        //If the value is the 3rd, 4th, or 5th dropdown...
        else if(val == "value3" || val == "value4" || val == "value5") {
            //Slide down both the forms
            $("#search1").slideDown("fast"); //Slide Down Effect
            $("#search2").slideDown("fast");
        } 
        //If the value is nothing (choice is selected)...
        else{
            //Slide up both forms
            $("#search1").slideUp("fast");
            $("#search2").slideUp("fast");
        }
    });
});​
我删除了你原来的
else
语句,因为它不需要