How do I execute a function after 5 sec from last keyup?

stack

I have a textarea and I'm trying to create a autosaved for that. I want to save the content of such a textarea if 5 sec passed and no key pressed:

function autosaving(){

    // save the value of text area into localstorage
    alert('saved');

}

And here is the textarea:

<textarea class="mytextarea" rows="4" cols="50"></textarea>

I want to execute that function 5 sec after inserted last character into that textarea. In other word, I want to run that function if 5 sec is passed and there isn't any new value in the textarea. How can I do that?

Sushanth --

Use a combination of keyUp and setTimeout

var timer;
$("textarea").on("keyup", function() {
    clearInterval(timer);
    timer = setTimeout(function() {
        autosaving();
    }, 5 * 1000);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

bind click and keyup of different target to do same function

来自分类Dev

How do I prevent my program from skipping html2pdf function?

来自分类Dev

How do I get a list of all the GitHub projects I've contributed to in the last year?

来自分类Dev

Jquery Execute function After third party function ends

来自分类Dev

In C#, how can I keep all my items in a listbox from changing to the color I set last?

来自分类Dev

How do I conditionally execute a resource in Powershell DSC based on a previous resource executing?

来自分类Dev

How do I take the last so many entries (skip) with Eloquent Query Builder in Laravel

来自分类Dev

How do I select only people who share last names? SQL

来自分类Dev

For each unique value of some groupid column, how do I get rows with last 3 dates?

来自分类Dev

Swift: How do I return a value within an asynchronous urlsession function?

来自分类Dev

How do I redirect the output of a system() function to a variable?

来自分类Dev

How do I use a Codeigniter method within my own function?

来自分类Dev

How do I turn a function variable into a div id name?

来自分类Dev

How do I use an extension function in another class? C#

来自分类Dev

How do I unit test a function that loops over objects?

来自分类Dev

How do I remove the background from this kind of image?

来自分类Dev

How do I use my Application Resources from another window?

来自分类Dev

How do I access a jQuery plugin variable from within method?

来自分类Dev

How do I change ImmutableSet from guava collections?

来自分类Dev

How do I get a value from an associative array using Swift

来自分类Dev

How do I rewrite / redirect from http to https in Go?

来自分类Dev

How do I access random elements from a vector in R studio?

来自分类Dev

How do i change from mouse to touch instead?

来自分类Dev

Do.call to execute a function on columns of data frame

来自分类Dev

Given the function `decode`, how can I do the inverse and write a function to `encode`?

来自分类Dev

How do I make this javascript function wait until I've scrolled x pixels down the page?

来自分类Dev

How to execute a GDB command from a string variable?

来自分类Dev

I have a few function overloads, each of which takes a different subclass; how do I check which function to use for a given object?

来自分类Dev

How can I propagate an exception thrown from an asynchronous function to an awaiting async void function?

Related 相关文章

  1. 1

    bind click and keyup of different target to do same function

  2. 2

    How do I prevent my program from skipping html2pdf function?

  3. 3

    How do I get a list of all the GitHub projects I've contributed to in the last year?

  4. 4

    Jquery Execute function After third party function ends

  5. 5

    In C#, how can I keep all my items in a listbox from changing to the color I set last?

  6. 6

    How do I conditionally execute a resource in Powershell DSC based on a previous resource executing?

  7. 7

    How do I take the last so many entries (skip) with Eloquent Query Builder in Laravel

  8. 8

    How do I select only people who share last names? SQL

  9. 9

    For each unique value of some groupid column, how do I get rows with last 3 dates?

  10. 10

    Swift: How do I return a value within an asynchronous urlsession function?

  11. 11

    How do I redirect the output of a system() function to a variable?

  12. 12

    How do I use a Codeigniter method within my own function?

  13. 13

    How do I turn a function variable into a div id name?

  14. 14

    How do I use an extension function in another class? C#

  15. 15

    How do I unit test a function that loops over objects?

  16. 16

    How do I remove the background from this kind of image?

  17. 17

    How do I use my Application Resources from another window?

  18. 18

    How do I access a jQuery plugin variable from within method?

  19. 19

    How do I change ImmutableSet from guava collections?

  20. 20

    How do I get a value from an associative array using Swift

  21. 21

    How do I rewrite / redirect from http to https in Go?

  22. 22

    How do I access random elements from a vector in R studio?

  23. 23

    How do i change from mouse to touch instead?

  24. 24

    Do.call to execute a function on columns of data frame

  25. 25

    Given the function `decode`, how can I do the inverse and write a function to `encode`?

  26. 26

    How do I make this javascript function wait until I've scrolled x pixels down the page?

  27. 27

    How to execute a GDB command from a string variable?

  28. 28

    I have a few function overloads, each of which takes a different subclass; how do I check which function to use for a given object?

  29. 29

    How can I propagate an exception thrown from an asynchronous function to an awaiting async void function?

热门标签

归档