jQuery - livequery 插件帮助
当用户更改单选按钮时,我将更新消息添加为表行。我遇到的事实是,一旦添加消息,它就没有我想象的功能,因为它是在页面加载后添加的。然后我发现 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,这里
应该是
其次,我建议不要使用 livequery 进行 fadeOut,但如果您要使用它,则此语法:
应该是:
first of all this bit here
should be
secondly, i recommend against livequery for the fadeOut, but if you are going to use it, this syntax:
should be:
不需要调用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.
使用最新版本的 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.
如果 setTimeout 的目标是淡出页面加载时存在的元素,那么您不需要涉及 livequery
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