当用户更改单选按钮时,我将更新消息添加为表行。我遇到的事实是,一旦添加了消息,它就没有我认为的功能,因为它是在页面加载之后添加的。然后我发现了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>如果我需要提供更多的信息,我将尝试这样做,并提前感谢您的帮助。
发布于 2009-10-15 21:46:42
首先,这里有一点
$('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>其次,我建议不要对fadeOut使用livequery,但是如果你打算使用它,下面的语法:
setTimeout($.livequery.function() {
$('.msgUpdate').fadeOut('normal');
}, 1000); // <-- time in milliseconds
});应该是:
$.livequery(function(){
setTimeout(function(){
$('.msgUpdate').fadeOut('normal');
},1000);
});发布于 2009-10-15 19:28:57
你不需要给window.setTimeout打电话吗?我不确定这是否有必要,但可能值得一试。
发布于 2009-10-15 20:03:46
使用最新版本的jQuery (1.3.X),您不需要使用livequery插件。你可以只使用$(“div”)点击(“.live”,等等...
我认为如果你看看jQuery的新的实时功能,你也许能够清理你的Javascript,这样它就更容易理解。
https://stackoverflow.com/questions/1574486
复制相似问题