jQuery - livequery 插件帮助

发布于 2024-08-07 17:20:44 字数 925 浏览 5 评论 0原文

当用户更改单选按钮时,我将更新消息添加为表行。我遇到的事实是,一旦添加消息,它就没有我想象的功能,因为它是在页面加载后添加的。然后我发现 livequery 插件似乎允许事后添加的元素与页面加载的元素具有相同的功能。

我的 click fadeout() 工作正常,但我似乎无法弄清楚刚刚添加的表行上的 setTimeout() 的语法。我知道当前的语法不正确,我把它留在了令我沮丧的地方。

<script>
  $(document).ready(function(){  
    $("input[@name='optInOut']").change(function(){
        $('#tblUpdates').append('<tr class="msgUpdate"><td colspan="2">added message0</td><td align="right"><img src="../Images/CCC/12-em-cross.png" class="imgClose" alt="close message" title="close message" /></td></tr>');
    });

    setTimeout($.livequery.function() {  
        $('.msgUpdate').fadeOut('normal');  
        }, 1000); // <-- time in milliseconds
    });

    $('img.imgClose').livequery('click', function(){
        $(this).parent().parent().fadeOut('normal');
  }); 
</script>

如果我需要提供更多信息,我会尝试这样做,并提前感谢您的帮助。

I add update messages as table rows when a user changes a radio button. I was running into the fact that once the message was added it didn't have the functionality that I thought it would since it was added after the page was already loaded. Then I found the livequery plugin that seemed to allow elements added after the fact to have the same functionality as elements loaded with the page.

I have the click fadeout() working correctly, but I can't seem to figure out the syntax for setTimeout() on the table row that was just added. I know the current syntax is NOT correct, and I left it at the point where I was frustrated.

<script>
  $(document).ready(function(){  
    $("input[@name='optInOut']").change(function(){
        $('#tblUpdates').append('<tr class="msgUpdate"><td colspan="2">added message0</td><td align="right"><img src="../Images/CCC/12-em-cross.png" class="imgClose" alt="close message" title="close message" /></td></tr>');
    });

    setTimeout($.livequery.function() {  
        $('.msgUpdate').fadeOut('normal');  
        }, 1000); // <-- time in milliseconds
    });

    $('img.imgClose').livequery('click', function(){
        $(this).parent().parent().fadeOut('normal');
  }); 
</script>

If I need to provide more information I will attempt to do so and thanks in advance for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

神爱温柔 2024-08-14 17:20:45

首先,这里

     $('img.imgClose').livequery('click', function(){
        $(this).parent().parent().fadeOut('normal');
}); 
</script>

应该是

     $('img.imgClose').livequery('click', function(){
        $(this).parent().parent().fadeOut('normal');
     });//<--- closes the livequery call
});//<--- closes document.ready
</script>

其次,我建议不要使用 livequery 进行 fadeOut,但如果您要使用它,则此语法:

setTimeout($.livequery.function() {  
        $('.msgUpdate').fadeOut('normal');  
        }, 1000); // <-- time in milliseconds
    });

应该是:

$.livequery(function(){
  setTimeout(function(){
     $('.msgUpdate').fadeOut('normal'); 
  },1000);
});

first of all this bit here

     $('img.imgClose').livequery('click', function(){
        $(this).parent().parent().fadeOut('normal');
}); 
</script>

should be

     $('img.imgClose').livequery('click', function(){
        $(this).parent().parent().fadeOut('normal');
     });//<--- closes the livequery call
});//<--- closes document.ready
</script>

secondly, i recommend against livequery for the fadeOut, but if you are going to use it, this syntax:

setTimeout($.livequery.function() {  
        $('.msgUpdate').fadeOut('normal');  
        }, 1000); // <-- time in milliseconds
    });

should be:

$.livequery(function(){
  setTimeout(function(){
     $('.msgUpdate').fadeOut('normal'); 
  },1000);
});
酒与心事 2024-08-14 17:20:45

不需要调用window.setTimeout吗?我不确定这是否有必要,但可能值得一试。

Don't you need to call window.setTimeout? I'm not sure if that is necessary, but it might be worth a try.

青柠芒果 2024-08-14 17:20:45

使用最新版本的 jQuery (1.3.X),您不需要使用 livequery 插件。你可以只使用 $("div").live("click" 等...

我想如果你看看 jQuery 的新 live 函数,你也许能够清理你的 Javascript,这样它就更容易理解了。

With the newest edition of jQuery (1.3.X) you do not need to use the livequery plugin. You can just use $("div").live("click",etc....

I think if you look at the new live function of jQuery you might be able to clean up you Javascript so that it is more understandable.

岁吢 2024-08-14 17:20:45

如果 setTimeout 的目标是淡出页面加载时存在的元素,那么您不需要涉及 livequery

setTimeout("$('.msgUpdate').fadeOut('normal');", 1000);

If the goal with the setTimeout is to fade elements that existed when the page was loaded, then you shouldn't need to involve livequery

setTimeout("$('.msgUpdate').fadeOut('normal');", 1000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文