<script language="javascript" src="js/settags.js"></script>
function AppTag(tagcode)
{
document.PostMessage.Message.value += tagcode;
}
function InsertTag(tagbegin,tagend)
{
if ((document.selection)&&(document.selection.type == "Text")) {
var range = document.selection.createRange();
var ch_text=range.text;
range.text = tagbegin + ch_text + tagend;
}
else
{
document.PostMessage.Message.value=tagbegin+document.PostMessage.Message.value+tagend;
document.PostMessage.Message.focus();
}
}
</script>
调用:
执行操作的图标按钮:
<a href="javascript:AppTag('[ImgFace1]')"><img src="./Images/Face/Face1.gif" border="0"></a>
<a href="javascript:InsertTag('[B]','[/B]')"><img src="./Images/tags/EditorBold.gif" alt="Bold" border="0"></a>
其中[ImgFace1],[B],[/B]为要插入的文字
var range = document.selection.createRange();
var ch_text=range.text;
这是得到文本框选中的文字
被操作的文本框:
<asp:TextBox ID="Message" Runat="server" MaxLength="100" TextMode="MultiLine" Rows="15" Width="100%" />