这是我的代码(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 页面的多个元素上声明相同的 id
。 id
对于文档
应该是唯一的。相反,请尝试将使用 navnum
作为 id
的 div 切换为将它们用作 class
。 class
名称可以在整个页面中共享。例如:
<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/