jQuery检查某人何时开始输入字段 [英] jquery to check when a someone starts typing in to a field

查看:61
本文介绍了jQuery检查某人何时开始输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('a#next').click(function() {
    var tags = $('input[name=tags]');

    if(tags.val()==''){

    tags.addClass('hightlight');  
    return false; 
    }else{
    tags.removeClass('hightlight');
    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
        return false;
    }
});

我希望上面的代码在有人开始输入标签输入后立即触发fadeIn.有人可以告诉我正确的方法或为我指出正确的方向吗?预先感谢

I would like the above code to fire the fadeIn as soon as somebody starts typing into the tags input. Can somebody tell me the correct way to do this or point me in the right direction? Thanks in advance

编辑

这是执行此操作的代码:

here is the code to do it:

$('input#tags').keypress(function() {

    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
});

我发现的唯一问题是光标不再显示在文本框中.我在做什么错了?

The only problem I've found is that my cursor no longer shows up in the text box. What am I doing wrong?

推荐答案

诸如淡入淡出之类的声音正在移动您的焦点,因此光标不再在那里.试试这个

Sounds like the fade is moving your focus, hence the cursor no longer being there. Try this

$('input#tags').keypress(function() {

    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
    $(this).focus();
});

这篇关于jQuery检查某人何时开始输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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