Reprise du message précédent :
Je te donne la fonction qui me sert à insérer des tags, c'est codé à l'arrache.
Mais c normal, je suis le seul à m'en servir (ça fonctionne avec mozilla, IE ça m'étonnerais) :
function insertt(openTag, closeTag) {
var input = document.forms['edit'].elements['TEXT'];
input.focus();
if(typeof input.selectionStart != 'undefined'){
var start = input.selectionStart;
var end = input.selectionEnd;
var scroll = input.scrollTop;
var pos;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + openTag + insText + closeTag + input.value.substr(end);
if(insText.length == 0){
pos = start + openTag.length;
}else{
pos = start + openTag.length + insText.length + closeTag.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
input.scrollTop = scroll;
}
} |
Ca fait tout ce que je veux (insérer le texte à partir du curseur, repositionner le curseur...).
Message édité par kalex le 22-04-2005 à 20:38:35