$('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。有人能告诉我这样做的正确方法还是指向正确的方向?提前致谢
编辑
这是执行此操作的代码:
$('input#tags').keypress(function() {
$('#formcont').fadeIn('slow');
$('#next').hide('slow');
});
我发现的唯一问题是我的光标不再显示在文本框中。我做错了什么?
答案 0 :(得分:9)
听起来褪色正在移动你的焦点,因此光标不再存在。试试这个
$('input#tags').keypress(function() {
$('#formcont').fadeIn('slow');
$('#next').hide('slow');
$(this).focus();
});
答案 1 :(得分:1)
您需要focus event。
$('a#next').focus(function() {
$('#formcont').fadeIn('slow');
});
答案 2 :(得分:0)
input#tags
是多余且浪费的。
$('#tags').keypress(function() {
$('#formcont').fadeIn('slow');
$('#next').hide('slow');
$(this).focus();
});