J'ai un textarea ...Spécification Où mise au point dans Textarea
<textarea>
Some writing here
*
Then some more on another line
</textarea>
Ce que je veux faire est de concentrer l'utilisateur où * est. Est-ce possible?
J'ai un textarea ...Spécification Où mise au point dans Textarea
<textarea>
Some writing here
*
Then some more on another line
</textarea>
Ce que je veux faire est de concentrer l'utilisateur où * est. Est-ce possible?
Utilisez la fonction suivante pour définir une sélection dans une zone de texte.
function setSelRange(inputEl, selStart, selEnd) {
if (inputEl.setSelectionRange) {
inputEl.focus();
inputEl.setSelectionRange(selStart, selEnd);
} else if (inputEl.createTextRange) {
var range = inputEl.createTextRange();
range.collapse(true);
range.moveEnd('character', selEnd);
range.moveStart('character', selStart);
range.select();
}
}
// From http://www.webmasterworld.com/forum91/4527.htm
Ainsi, dans votre cas, vous pouvez rechercher la position du caractère *
et utiliser cette valeur dans un appel comme celui-ci:
var pos = 17; // Set this to the position of the * character.
setSelRange(document.getElementById('textareaId'), pos, pos);
juste pour rendre votre fardeau plus léger.
<textarea id="myarea">
Some writing here
*
Then some more on another line
</textarea>
function FocusMe(what){ // what = character to be focused(in your case *)
var cFocus = document.getElemenById("myarea").innerHTML;
var pos = cFocus.indexOf(what);
setSelRange(document.getElementById('myarea'), pos, pos); //Jame's answer above.
}
J'ai eu besoin de peaufiner ce que je voulais mais ça fonctionne bien. Merci. –