jquery-ui - DIV 上的单击事件在 IE 中不起作用

标签 jquery-ui internet-explorer html click

这是我的代码(html)

<div id="navig" style="font-family: arial; font-size: 12px; font-weight: normal;">
<div id="navfirst"><a href="#"  style="text-decoration: none;">First</a></div>
<div id="navnum"><a href="#"  style="text-decoration: none;">1</a></div>
<div id="navnum"><a href="#"  style="text-decoration: none;">2</a></div>
<div id="navnum"><a href="#"  style="text-decoration: none;">3</a></div>
<div id="navnum"><a href="#"  style="text-decoration: none;">4</a></div>
<div id="navnum"><a href="#"  style="text-decoration: none;">5</a></div>
<div id="navlast"><a href="#"  style="text-decoration: none;">Last</a></div>


 $( document ).ready(function( ) {
 $('div #navnum').click( function ( ) {
    var divtext =  $(this).text( ) ;
    $( this ).css('background-color', '#f99');
    $( this ).prevAll( ).css('background-color', '');
    $( this ).nextAll( ).css('background-color', '');
    $('#pgnum').html( '<p>clicked page number ' + divtext  + '</p>' ).fadeIn( 100 );
});

 });

在 firefox 和 chrome 上工作正常,但在 IE 8 上不行,如何让它在 IE 上工作

最佳答案

您不应该在 HTML 页面的多个元素上声明相同的 idid 对于文档 应该是唯一的。相反,请尝试将使用 navnum 作为 id 的 div 切换为将它们用作 classclass 名称可以在整个页面中共享。例如:

<div class="navnum"><a href="#"  style="text-decoration: none;">1</a></div>

然后对于您的点击处理程序:

$('div.navnum').click( function ( )

我做了一个jsFiddle你可以在 IE 中测试。

关于jquery-ui - DIV 上的单击事件在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14428967/

相关文章:

jquery - 可对事件进行排序获取当前可删除项

javascript - 覆盖对话框的问题

html - IFRAME 在 IE8 中不会显示 100% 高度,但在 IE11 和 Firefox 中正常

html - 允许在 IE11 中禁用的字段集上溢出滚动

javascript - 我对所有值求和,但为什么它不适用于所有动态总计字段

jQuery datepicker 禁用用户选择

jquery - 刷新可拖动遏制

javascript - IE下拉菜单问题

html - 如何让我的 div 中的图像在悬停时改变不透明度?

html - 你如何在伪元素之后::之前获得缩进?