Delay changing innerHTML text using jQuery

前端 未结 2 1318
自闭症患者
自闭症患者 2021-01-20 15:05

So I\'ve got a pretty simple button that basically toggles a form on and off - we\'ll be using this on our site since we\'re doing an update and would like feedback availabl

2条回答
  •  旧巷少年郎
    2021-01-20 15:56

    You can achieve this by using setTimeout():

    var timeout;
    $('#feedbackLink').hover(
        function() {
            clearTimeout(timeout);
            timeout = setTimeout(function() {
                $("#feedbackLink").html('Send us a quick message!');
            }, 2000); // change the HTML after 2 seconds
        },
        function() {
            clearTimeout(timeout);
            timeout = setTimeout(function() {
                $("#feedbackLink").html('How can we improve this page?');
            }, 2000); // change the HTML after 2 seconds
        }
    );
    

提交回复
热议问题