First method
You can use javascript, get the focus event, and set the value in placeholder and onblur to return to the previous value, and you choose which element you want to do this using querySelector.
var elemento = document.querySelector("input");
elemento.onfocus = function(){
elemento.placeholder = "apenas número";
};
elemento.onblur = function(){
elemento.placeholder = "telefone";
};
Quando focar nesse inpute gostaria de trocar o texto do placeholder para por exemplo "apenas números"
<br><br>
<input type="tel" placeholder="telefone" name="" id="">
Second method
I've created a new way in which you'll only worry about javascript once, just put the alter-placeholder class on the element and the placeholder-focus and placeholder-blur attributes by defining the text, see an example:
var elemento = document.querySelector(".alter-placeholder");
elemento.onfocus = function(){
elemento.placeholder = this.getAttribute('data-placeholder-focus');
};
elemento.onblur = function(){
elemento.placeholder = this.getAttribute('data-placeholder-blur');
};
Quando focar nesse inpute gostaria de trocar o texto do placeholder para por exemplo "apenas números"
<br><br>
<input
placeholder="telefone"
data-placeholder-blur="telefone"
data-placeholder-focus="apenas número"
class="alter-placeholder"
type="tel" name="" id="">