D
D
Dima2018-03-14 17:27:02
JavaScript
Dima, 2018-03-14 17:27:02

Solution this in setinterval?

jsfiddle.net/0ajmmk1d/1

there is a problem between setinterval and this. how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2018-03-14
Dolgoter @DDolgy

Choice of taste:

$("input").keyup(function () {
    setTimeout(() => {
        $(this).next('input').focus()
    }, 2000);
});

$("input").keyup(function () {
    function onTimeOut() {
        $(this).next('input').focus()
    }
    setTimeout(onTimeOut.bind(this), 2000);
});

$("input").keyup(function () {
    const $input = $(this).next('input');
    setTimeout(function () {
        $input.focus()
    }, 2000);
});

$("input").keyup(function () {
    const $input = $(this).next('input');
    setTimeout(function ($elem) {
        $elem.focus()
    }, 2000, $input);
});

And a couple of options for varying degrees of nausea and hipsterism.
PS At the moment, the problem is that you are not passing a function to setTimeout :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question