2012-02-07 39 views
0

當點擊輸入字段時,我正在執行一些jquery。如果我點擊進出,真的很快它把所有東西都擰緊了。如何在開始新操作前讓當前操作完成?等待jquery操作完成,然後開始新的焦點/模糊功能

$("#title, #desc").focus(function() { 

}).blur(function() { 

    var frameHtml = $('.liveDemoFrame').html(); 
    var liveDemoFrame = $('.liveDemoFrame'); 
    var previewFrame = $('#previewFrame'); 

    previewFrame.remove(); 
    liveDemoFrame.append(frameHtml).hide(); 
    $('#previewFrame').hide(); 
    liveDemoFrame.show().append('<p id="loading">Loading...</p>'); 

    setTimeout(function() { 
     $('#loading').remove(); 
     $('#previewFrame').fadeIn(); 
    }, 1000); 

}); 

回答

0

某處全局(即高於你的選擇),在您的blur()

myTimeout = setTimeout(function... 

而在focus()

clearTimeout(myTimeout); 

var myTimeout; 

那麼現在,當如果你關注元素,它會失去fadeIn()調用。