使用fadeIn无法正确显示jQuery文本 [英] jQuery text not showing properly using fadeIn

查看:89
本文介绍了使用fadeIn无法正确显示jQuery文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了这个问题,但找不到适用于我的解决方案。

I searched for this problem but couldn't find solution that works for me.

我正在尝试做四个复选框,从中只能选择三个。当选择第四个复选框时,会显示一条淡入淡出的消息,通知用户有关限制的信息。
这是文本中淡出的部分:

I'm trying to do four checkboxes, from which only three can be selected. And when fourth checkbox is selected there is a faded in message, which informs the user about the limit. This is the part that fades in the text:

$('#warning').fadeIn('slow',function() {
        $(this).stop().text("(You can't have more than 3 selected options)");
        setTimeout(function() {
            $("#warning").fadeOut(300);
        }, 2500);
});

我无法延迟,所以我使用了setTimeout。
我无法理解为什么第一次点击第四个复选框时,该消息会立即显示uo。我究竟做错了什么?

I couldn't do it with a delay, so I used setTimeout. I can't understand why the first time the fourth checkbox is clicked, the message shows uo instantly. What am I doing wrong?

还有一种方法可以延迟而不是setTimer吗?

And also is there a way to do it with a delay instead of setTimer?

这是一个链接整个代码: http://jsfiddle.net/e5kns/

Here is a link to the whole code: http://jsfiddle.net/e5kns/

推荐答案

尝试将其添加到脚本的开头:

Try adding this to the start of the script:

$('#warning').text("(You can't have more than 3 selected options)");
$('#warning').show();
$('#warning').hide();

这篇关于使用fadeIn无法正确显示jQuery文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆