2016-09-21 70 views
4

我在jQueryUI的焦點輸入有問題。我在按鈕上使用了hover()方法,它正在工作,但focus()對輸入不起作用。我不知道爲什麼。這裏的代碼和小提琴焦點()jQueryUI不工作

$(document).ready(function(){ 
    $('input[type=text]').focus(function(){ 
    $(this).stop().animate({ 
     backgroundColor: '#000' 
    }, 1000); 
    }, function() { 
    $(this).stop.animate({ 
     backgroundColor: 'rgba(0,0,0,0)' 
    }, 1000); 
    }); 
}); 

而這裏的小提琴

https://jsfiddle.net/ssa7sh4f/12/

+0

你傳遞2個處理器集中? – 2016-09-21 22:29:54

+0

我從我的懸停按鈕中複製了該文件。 – falauthy

回答

1

我不知道你想要做什麼。但在你的代碼中,你正在分配2個處理程序來集中(就像@squint指出的那樣)。

相反,你可以一個處理程序focus()和一個分配給focusout(),像這樣:

$(document).ready(function(){ 
    $('input[type=text]').focus(function(){ 
    $(this).css('background-color', 'black'); 
    }).focusout(function() { 
    $(this).css('background-color', 'white'); 
    }); 
}); 

https://jsfiddle.net/g6997gnh/