複製代碼 代碼如下:<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%" />