jQuery-如何在添加类后刷新选择器
我在JSFIDLE中制作了这个示例来演示我的问题: 看看灰色类是如何添加的,但当你再次悬停时,它不会应用左边距。我猜这是因为$'.block.grey'选择器是在添加类is grey类之前声明的 在添加类后,是否仍然可以使用$'.block.grey'选择器重新解析dom 任何帮助都会很好,干杯 编辑: 我有一个更复杂的例子jQuery-如何在添加类后刷新选择器,jquery,jquery-selectors,Jquery,Jquery Selectors,我在JSFIDLE中制作了这个示例来演示我的问题: 看看灰色类是如何添加的,但当你再次悬停时,它不会应用左边距。我猜这是因为$'.block.grey'选择器是在添加类is grey类之前声明的 在添加类后,是否仍然可以使用$'.block.grey'选择器重新解析dom 任何帮助都会很好,干杯 编辑: 我有一个更复杂的例子 $('.accordion h3').not('.ui-state-active').find('a').live('hover', function(){ 其中动态添加
$('.accordion h3').not('.ui-state-active').find('a').live('hover', function(){
其中动态添加ui状态活动类。bitsMix指出,这段代码正在使a变得活跃起来。所以我把它更新为
$('.accordion h3').live('hover', function(){
$(this).not('.ui-state-active').find('a').stop().animate({
而且它有效!谢谢大家 您可以使用
你可以用
现场演示:
直播演示:您需要将直播添加到以下内容:
$('.block.grey').live( "hover",function(){
$(this).css('margin-left', '10px');
});
您需要将live添加到中,如下所示:
$('.block.grey').live( "hover",function(){
$(this).css('margin-left', '10px');
});
来了:
$('.block').hover(function(){
$(this).css('background-color', '#CCC');
$(this).addClass('grey');
});
$('.block.grey').live('hover',function(){
$(this).css('margin-left', '10px');
});
来了:
$('.block').hover(function(){
$(this).css('background-color', '#CCC');
$(this).addClass('grey');
});
$('.block.grey').live('hover',function(){
$(this).css('margin-left', '10px');
});
`$'.accordion h3'.not'.ui state active'.find'a'.live'hover',function`将悬停到a,而不是h3`$'.accordion h3'.not'.ui state active'.find'a'.live'hover',function`将悬停到a,而不是h3