zoukankan      html  css  js  c++  java
  • 在光标处添加文字,或对选择的文字进行更改(JS:TextRange)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        
    <title>Untitled Page</title>
        
    <script language="javascript" type="text/javascript">
        
    function Blod()
        
    {
            Format(
    "粗体","'''");
        }

        
    function Italic()
        
    {
            Format(
    "斜体","''");
        }

        
    function Format(formatName,format)
        
    {        
            
    var textarea = document.getElementById("txaContent");
            
    if(textarea.pos != null)
            
    {
                
    var s = textarea.pos.text;
                
    if(s == null || s == 'undefined'||== '')
                
    {
                    s 
    = formatName ;
                }

                s 
    = format + s + format;
                textarea.pos.text 
    = s;
            }

            
    else
            
    {
                textarea.value 
    += format+formatName+format;
            }

        }

        
    </script>
    </head>
    <body>
    <textarea id="txaContent" cols="20" rows="20" onselect="this.pos = document.selection.createRange();" onclick="this.pos = document.selection.createRange();" onkeyup="this.pos = document.selection.createRange();" ></textarea>
    <input type="button" onclick="Blod()" value="Blod" id="btnBlod" />
    <input type="button" onclick="Italic()" value="Italic" id="btnItalic" />
    </body>
    </html>
  • 相关阅读:
    项目Alpha冲刺(团队)-第七天冲刺
    NOIP模拟赛[补档]
    关于补档
    noip2017集训测试赛(三) Problem B: mex [补档]
    初赛准备 [补档]
    记录 [补档]
    Leave It Behind and Carry On ---- 高一下期末考反思 [补档]
    NOIP 2017 赛后反思 [补档]
    囤题 [补档]
    组合游戏学习笔记 [补档]
  • 原文地址:https://www.cnblogs.com/think/p/328907.html
Copyright © 2011-2022 走看看