2017-08-27 51 views
1

对于我的项目,我使用两个浏览器IE(ver11)和chrome。未在IE上触发jQuery点击事件

我在我的页面上创建按钮并将点击事件绑定到每个按钮。

在这里,我对UI创建按钮:

<table id="miniToolbar"> 
     <tbody> 
     <tr>    
      <td><button type="button" class="button_air-medium"><div id="showToolbar" class="miniToolbarContant showMenu"></div></button></td> 
      <td><div id="toolbarArea" class="toolbarArea" data-Owner="dera" data-Date="11/2016"> 
       <img id="toolbarTitle" width="15px" height="15px" src="../stdicons/threePoints.png"> 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <button type="button" class="button_air-medium"><div id="showLayers" class="miniToolbarContant showLayers"></div></button> 
      </td> 
     </tr>          
     <tbody> 
    </table> 

这里是JavaScript事件一定到每个按钮:

$(function() { 
    $('#showToolbar').click(function(){ 
     $(this).toggleClass('rotate'); 
     $('#toolbarArea').toggle('slide'); 

     $(this).toggleClass('showMenu');    
     $(this).toggleClass('hideMenu'); 
    }); 

    $('#showLayers').click(function(){ 
     $(this).toggleClass('rotate');   
     hideLagend();   
     $('#InfoBand').toggle('slide');  

     $(this).toggleClass('hideLayers');   
     $(this).toggleClass('showLayers'); 
    });    
}); 

当我使用铬,我按一下按钮适当的方法被解雇了,它的工作完美。 但是,当我打开IE浏览器,并点击按钮没有方法被解雇,我没有在控制台中出现任何错误。

任何想法为什么方法不会触发IE浏览器?

回答

1

好像已知的.click事件未在IE问题上正确注册。

尝试使用.on("click"...而不是.click

$(function() { 
    $('#showToolbar').on('click', function() { 
     $(this).toggleClass('rotate'); 
     $('#toolbarArea').toggle('slide'); 

     $(this).toggleClass('showMenu');    
     $(this).toggleClass('hideMenu'); 
    }); 

    $('#showLayers').on('click', function() { 
     $(this).toggleClass('rotate');   
     hideLagend();   
     $('#InfoBand').toggle('slide');  

     $(this).toggleClass('hideLayers');   
     $(this).toggleClass('showLayers'); 
    });    
}); 
+0

每[jQuery的文档】(https://api.jquery.com/click/),'.click'方法是用于'。对快捷方式( “点击”,所以你的建议只会回到他已经有的东西 –

+0

@BenRondeau没有.IE已经知道'.click'的问题。请在downvoting之前查看事实。 –

+0

这个bug的文档? –