Mam pewien problem:
kod js:
Kod
function add_tag(stag, etag) {
obj = document.form.text;
r = document.selection.createRange();
if(document.selection.type == 'Text' && (obj.value.indexOf(r.text) != -1)) {
a = r.text;
r.text = stag + r.text + etag;
if (obj.value.indexOf(document.selection.createRange().text) == -1) {
document.selection.createRange().text = a;
}
}
else {
insert_tag(obj, stag + etag);
}
obj.focus();
}
function insert_tag(textel, text) {
if (textel.createTextRange && textel.caretPos) {
var caretPos = textel.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else {
textel.value = textel.value + text;
}
textel.focus();
}
obj = document.form.text;
r = document.selection.createRange();
if(document.selection.type == 'Text' && (obj.value.indexOf(r.text) != -1)) {
a = r.text;
r.text = stag + r.text + etag;
if (obj.value.indexOf(document.selection.createRange().text) == -1) {
document.selection.createRange().text = a;
}
}
else {
insert_tag(obj, stag + etag);
}
obj.focus();
}
function insert_tag(textel, text) {
if (textel.createTextRange && textel.caretPos) {
var caretPos = textel.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else {
textel.value = textel.value + text;
}
textel.focus();
}
Kod HTML:
<input type="button" class="style3" style="background-color: white; padding-left: 3px; padding-right: 3px; font-weight: bold; cursor: hand" onClick="insert_tag("[b]","[/b]")" value="B">
Efekt:
http://ociu.100tka.net/book/index.php?action=form
Sprostowanie:
Po kliknięciu na button B, I lub U nie wskakuje tag :/
Help !