I m having some trouble with this script. It is suposed to add html tags to a selected text region in a text box. While live viewing in dreamweaver it works just fine. Exactly how it s suposed to. In browser it does nothing.
任何想法?
该职能称为onclick=“formatText(content, b)”
。
function formatText(el, tag) {
var selectedText = document.selection ? document.selection.createRange().text
: el.value.substring(el.selectionStart, el.selectionEnd);
alert(selectedText);
if (selectedText != ) {
var newText = < + tag + > + selectedText + </ + tag + > ;
el.value = el.value.replace(selectedText, newText);
document.getElementById(el).focus();
} else {
if (document.getElementById(tag).value == "0") {
document.getElementById(tag).value = "1";
document.getElementById(el).value = document.getElementById(el).value
+ "<" + tag + ">";
document.getElementById(el).focus();
} else {
document.getElementById(tag).value = "0";
document.getElementById(el).value = document.getElementById(el).value
+ "</" + tag + ">";
document.getElementById(el).focus();
}
}
}