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>
  • 相关阅读:
    深度学习模型参数计算
    keras多输出多输出示例(keras教程一)
    keras可视化报错:OSError: `pydot` failed to call GraphViz.Please install GraphViz问题解决
    git版本管理,git tag
    python封装自己的模块,pip install安装到python环境
    如何理解Virtual DOM
    使用 Hbuilder 连接手机调试移动端项目
    js 常用排序
    博客漂浮的小人
    开发者必备Linux命令
  • 原文地址:https://www.cnblogs.com/think/p/328907.html
Copyright © 2011-2022 走看看