<script language="javascript" src="js/settags.js"></script>
function AppTag(tagcode)
{
document.PostMessage.Message.value += 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]为要插入的文字
其中[ImgFace1],[B],[/B]为要插入的文字
var range = document.selection.createRange();
var ch_text=range.text;
这是得到文本框选中的文字
var ch_text=range.text;
这是得到文本框选中的文字
被操作的文本框:
<asp:TextBox ID="Message" Runat="server" MaxLength="100" TextMode="MultiLine" Rows="15" Width="100%" />
博客展示了使用JavaScript实现文本框插入文字的功能。定义了AppTag和InsertTag函数,前者用于在文本框追加文字,后者可在选中文字前后插入指定标签。还给出了调用示例,通过图标按钮触发操作,同时介绍了获取文本框选中文字的代码。
3533

被折叠的 条评论
为什么被折叠?



