隐藏Div内的Div

时间:2013-04-07 05:30:05

标签: jquery html

我不确定为什么以下代码不会在我的div中隐藏我的两个div用于我的内容。有人可以查看我的代码吗?代码不会隐藏下面的div。感谢

好的,这是我编辑过的代码。在初始化加载时,两个表单都显示在选择类型下,当我选择经销商/客户时,正确的表单显示并选择类型,然后在您选择一个后显示Nothing。我如何让它最初隐藏一切?感谢

<div id="contentArea">
            <form action="xxxxx.php" method="post" onsubmit="return checkStuff();" enctype="multipart/form-data">
                Warranty Registration Type:<br/>
                <select id="select"> 
                    <option value ="#blank">Select Type</option>
                    <option value ="#dealerform">Dealer</option>
                    <option value ="#customerform">Customer</option>
                </select>
                <br/>
                <br/>
                <div id="dealerform">
                    Dealer Name:   <input type="text" name="dealername"> <br/>
                    Dealer Address:  <input type="text" name="dealeradd"> <br>
                </div>
                <div id="customerform">
                    First Name:  <input type="text" name="firstname"> <br>
                    Last Name:  <input type="text" name="lastname"> <br>
                </div>
                <script>
                $(document).ready(function(){
                    $('#select').change(function(){
                        $('#dealerform,#customerform').hide();
                        $($(this).find('option:selected').attr('value')).show();
                    });
                });
                </script>

2 个答案:

答案 0 :(得分:3)

可能是因为您的选择没有ID&#39;选择&#39;您在更改事件中使用的内容。

                <select id="select"> 
                    <option value ="#dealerform">Dealer</option>
                    <option value ="#customerform">Customer</option>
                </select>

答案 1 :(得分:0)

嘿,你应该写这样的

 $($(this).find('option:selected').attr('value')).show();

而不是

 $($(this).find('option:selected').attr('id')).show();

这样相应的div会隐藏当然其他人说需要在select之前添加id或删除#

$('select').change(....)