2010-08-22 66 views
1

我有一个选择菜单,当单击一个选项时显示/隐藏“livetransopts”div。在Firefox,Chrome等工作正常,但在IE浏览器没有人能帮助我吗?隐藏/显示jQuery中不工作在IE

<select> 
    <option class="hidelivetrans" value="No">No - Don't transfer the call</option> 
       <option class="showlivetrans" value="Yes">Yes - Transfer the call</option> 
       </select> 
       </div> 
       </div> 
       <!--Live transfer yes/no field--> 

       <script type="text/javascript"> 
       $(document).ready(function() { 
        $('.livetransopts').hide(); 

     $(".showlivetrans").click(function(){ 
          $(".livetransopts").show('slow');   
             }); 
     $(".hidelivetrans").click(function(){ 
          $(".livetransopts").hide('slow');   
             }); 
    }); 
       </script> 

       <!--live trans opts--> 
       <div class="livetransopts"> 
    <!--content here--> 
    </div> 

回答

0

这样做会“改变”事件绑定到

$(function(){ 

    var myDiv = $(".livetransopts"); 


    $("select").change(function(){ 
    if (this.value=="Yes") 
     myDiv.show('slow'); 
    else 
     myDiv.hide('slow'); 
    }); 

}); 
+1

使用'this.value'是更有效,因为它不会导致另一个jQuery对象的创建正确的方法。另外,缓存'$('。livetransopts')' – 2010-08-22 08:06:44