2013-04-07 59 views
0

我不确定为什么下面的代码不会将我的两个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> 
+0

' $('#select')'应该是'$('select')' – SRy 2013-04-07 05:35:27

+0

您的HTML标记无效。 – Eli 2013-04-07 05:37:19

回答

3

可能是因为您的选择没有在change事件中使用的id'select'。

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

你能看看我更新的代码/评论吗? – Intelwalk 2013-04-07 23:16:03

0

嘿,你应该写这样的

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

,而不是这个

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

,使得对应的div将ofcourse隐藏的人说需要添加ID为选择或之前删除#选择

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