|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<script type="text/javascript" language="javascript">
function fett()
{
text = prompt("<b>xxx</b>","");
if(text!="")
{
text = "<b>"+ text +"</b>";
document.neu.nachricht.value += text;
}
}
function italic()
{
text = prompt("<i>xxx</i>","");
if(text!="")
{
text = "<i>"+ text +"</i>";
document.neu.nachricht.value += text;
}
}
function underline()
{
text = prompt("<u>xxx</u>","");
if(text!="")
{
text = "<u>"+ text +"</i>";
document.neu.nachricht.value += text;
}
}
</script>
|
|
|
Quellcode |
1 2 3 4 5 |
<input type="button" value="Fett" onclick="fett()"> <input type="button" value="Kursiv" onclick="italic()"> <input type="button" value="Unterstr." onclick="underline()"> <br> <textarea name="nachricht" cols="50" rows="10" onkeyup="storeCaret(this);" onclick="storeCaret(this);" onselect="storeCaret(this)"></textarea> |
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
<!--
function insert(aTag, eTag) {
var input = document.forms['neu'].elements['nachricht'];
input.focus();
/* für Internet Explorer */
if(typeof document.selection != 'undefined') {
/* Einfügen des Formatierungscodes */
var range = document.selection.createRange();
var insText = range.text;
range.text = aTag + insText + eTag;
/* Anpassen der Cursorposition */
range = document.selection.createRange();
if (insText.length == 0) {
range.move('character', -eTag.length);
} else {
range.moveStart('character', aTag.length + insText.length + eTag.length);
}
range.select();
}
/* für neuere auf Gecko basierende Browser */
else if(typeof input.selectionStart != 'undefined')
{
/* Einfügen des Formatierungscodes */
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
/* Anpassen der Cursorposition */
var pos;
if (insText.length == 0) {
pos = start + aTag.length;
} else {
pos = start + aTag.length + insText.length + eTag.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
}
/* für die übrigen Browser */
else
{
/* Abfrage der Einfügeposition */
var pos;
var re = new RegExp('^[0-9]{0,3}$');
while(!re.test(pos)) {
pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
}
if(pos > input.value.length) {
pos = input.value.length;
}
/* Einfügen des Formatierungscodes */
var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
}
}
//-->
</script>
</head>
<body>
<form name="neu" action="">
<textarea name="nachricht" cols="30" rows="10"></textarea>
<br>
<input type="button" value="Fett" onClick="insert('[b]', '[/b]')">
<input type="button" value="Kursiv" onClick="insert('[i]', '[/i]')">
<input type="button" value="Unterstrichen" onClick="insert('[u]', '[/u]')">
</form>
</body>
</html>
|
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »Daniel« (4. Januar 2009, 22:22)
- Brauche eine genauere Definition
Zitat
Original von Staubwolke
Sonst kann man vielleicht auch das hier vom Forum nehmen?!