Javascript ajouter valeur onclick="insertTag&
Résolu/Fermé
darkchristophetd
Messages postés
1100
Date d'inscription
mardi 26 février 2008
Statut
Contributeur
Dernière intervention
14 novembre 2010
-
26 nov. 2008 à 19:45
RAD ZONE Messages postés 5205 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 19 avril 2020 - 27 nov. 2008 à 20:29
RAD ZONE Messages postés 5205 Date d'inscription samedi 20 janvier 2007 Statut Contributeur Dernière intervention 19 avril 2020 - 27 nov. 2008 à 20:29
A voir également:
- Javascript ajouter valeur onclick="insertTag&
- Onclick javascript - Astuces et Solutions
- Telecharger javascript - Télécharger - Langages
- Javascript round ✓ - Forum Javascript
- Pièce 2 euros dessin bonhomme valeur ✓ - Forum Loisirs / Divertissements
- Vba récupérer valeur cellule ✓ - Forum VB / VBA
3 réponses
RAD ZONE
Messages postés
5205
Date d'inscription
samedi 20 janvier 2007
Statut
Contributeur
Dernière intervention
19 avril 2020
1 347
26 nov. 2008 à 22:29
26 nov. 2008 à 22:29
Voila un exemple
MAIS en general on s en sert plutot pour des tag html !
exemple
RAD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>insertion par insertTag dans un textarea
</title>
<script type="text/javascript">
//<![CDATA[
<!--
function insertTag(startTag, endTag, textareaId, tagType) {
var field = document.getElementById(textareaId);
field.focus();
if (window.ActiveXObject) {
var textRange = document.selection.createRange();
var currentSelection = textRange.text;
} else {
var startSelection = field.value.substring(0, field.selectionStart);
var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
var endSelection = field.value.substring(field.selectionEnd);
field.focus();
}
if (window.ActiveXObject) {
textRange.text = startTag + currentSelection + endTag;
} else {
field.value = startSelection + startTag + currentSelection + endTag + endSelection;
}
}
//-->
//]]>
</script>
</head>
<body><h1>
<span>Texte insertion par insertTag dans un textarea
</span></h1>
<div>
<p>
<span>
<input type="button" value="Texte insertion par insertTag" onclick="insertTag('Lorem ipsum dolor sit amet consectetuer at nulla leo vel lacus. Vestibulum nibh urna vel rhoncus amet vel Sed Maecenas risus at.', '', 'textarea', '')" />
</span>
</p>
</div>
<span>
<textarea id="textarea" cols="100" rows="10">
</textarea>
</span>
</body>
</html>
MAIS en general on s en sert plutot pour des tag html !
exemple
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>insertion par insertTag dans un textarea
</title>
<script type="text/javascript">
//<![CDATA[
<!--
function insertTag(startTag, endTag, textareaId, tagType) {
var field = document.getElementById(textareaId);
field.focus();
if (window.ActiveXObject) {
var textRange = document.selection.createRange();
var currentSelection = textRange.text;
} else {
var startSelection = field.value.substring(0, field.selectionStart);
var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
var endSelection = field.value.substring(field.selectionEnd);
}
if (window.ActiveXObject) {
textRange.text = startTag + currentSelection + endTag;
textRange.moveStart('character', -endTag.length-currentSelection.length);
textRange.moveEnd('character', -endTag.length);
textRange.select();
} else { // Ce n'est pas IE
field.value = startSelection + startTag + currentSelection + endTag + endSelection;
field.focus();
field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
}
}
//-->
//]]>
</script>
</head>
<body><h1>
<span>Html tag insertion par insertTag dans un textarea
</span></h1>
<div>
<p>
<span>
<input type="button" value="Gras" onclick="insertTag('<b>', '</b>', 'textarea')" />
<input type="button" value="Souligner" onclick="insertTag('<u>', '</u>', 'textarea')" />
<input type="button" value="Barrer" onclick="insertTag('<del>', '</del>', 'textarea')" />
<input type="button" value="Italique" onclick="insertTag('<i>', '</i>', 'textarea')" />
<input type="button" value="Centrer" onclick="insertTag('<p align=\'center\'>', '</p>', 'textarea')" />
<input type="button" value="Droite" onclick="insertTag('<p align=\'right\'>', '</p>', 'textarea')" />
</span>
</p>
</div>
<span>
<textarea id="textarea" cols="100" rows="10">
</textarea>
</span>
</body>
</html>
RAD
darkchristophetd
Messages postés
1100
Date d'inscription
mardi 26 février 2008
Statut
Contributeur
Dernière intervention
14 novembre 2010
459
27 nov. 2008 à 20:08
27 nov. 2008 à 20:08
je vais essayer merci beaucoup
darkchristophetd
Messages postés
1100
Date d'inscription
mardi 26 février 2008
Statut
Contributeur
Dernière intervention
14 novembre 2010
459
27 nov. 2008 à 20:20
27 nov. 2008 à 20:20
Génial !!!
merci bcp ça marche nickel :DD
merci bcp ça marche nickel :DD
RAD ZONE
Messages postés
5205
Date d'inscription
samedi 20 janvier 2007
Statut
Contributeur
Dernière intervention
19 avril 2020
1 347
27 nov. 2008 à 20:29
27 nov. 2008 à 20:29
:-))
j ai mis resolu
a+
RAD
j ai mis resolu
a+
RAD