Имитация ввода текста в input JS
Нужно сделать имитацию ввода текста в placeholder, Вот так получаю undifined
function setText(elem, text, speed) {
var e = document.querySelector(elem);
var i = 0,
int = setInterval(function() {
if(i == text.length){
clearInterval(int);
e.text = 0;
};
e.value = e.setAttribute('placeholder', text); // Текст от начала до текущей позиции
i++;
}, speed);
e.focus();
e.onblur = function() { clearInterval(int) };
};
setText('#search_input', 'Введите запрос для поиска', 300);
Ответы (1 шт):
Автор решения: WebFox
→ Ссылка
Вот вроде-бы то,
function setText(elem, text, speed) {
const e = document.querySelector(elem);
let i = 0;
let int = setInterval(function () {
if (i === text.length - 1) {
clearInterval(int);
e.text = 0;
}
e.setAttribute('placeholder', text); // Текст от начала до текущей позиции
e.value += text[i];
i++;
}, speed);
e.focus();
e.onblur = function () {
clearInterval(int)
};
};
setText('#search_input', 'Введите запрос для поиска', 300);