Home >Web Front-end >JS Tutorial >Get the text selected in the text box and dynamically insert the js code of the text_form special effects

Get the text selected in the text box and dynamically insert the js code of the text_form special effects

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 19:18:081147browse
复制代码 代码如下:

 
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(); 
 } 

 
 
调用:

执行操作的图标按钮:


其中[ImgFace1],[B],[/B]为要插入的文字
 var range = document.selection.createRange();
 var ch_text=range.text;
这是得到文本框选中的文字

被操作的文本框:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn