• Demo 示例控制输入光标位置


    <!DOCTYPE html>
    <html>
    <head>
        <meta charset=utf-8 />
        <meta name="author" content="http://weibo.com/zswang" />
        <title>Demo 示例控制输入光标位置</title>
        <style>
             
        </style>
    </head>
    <body>
        <input id="editor" type="text" value="1234" />
        <input id="left" type="button" value="left" >
        <input id="right" type="button" value="right" >
        <script>
    void function(){
        function setSelection(editor, pos){
            if (editor.setSelectionRange){
                editor.focus();
                editor.setSelectionRange(pos, pos);
            } else if (editor.createTextRange){
                var textRange = editor.createTextRange();
                textRange.collapse(true);
                textRange.moveEnd("character", pos);
                textRange.moveStart("character", pos);
                textRange.select();
            }
        }
       
        var editor = document.getElementById('editor');
        document.getElementById('left').onclick = function(){
            setSelection(editor, 0);
        }
        document.getElementById('right').onclick = function(){
            setSelection(editor, editor.value.length);
        }
    }();
        </script>
    </body>
    </html>
    $("#db_name").bind("mousemove keyup",function(){
    var editor=document.getElementById('db_name');
    var val=editor.value;
    setSelection(editor, val.length); //光标控制在右边
    //setSelection(editor, 0); //光标控制在左边
    })

    资料来源:http://bbs.csdn.net/topics/380246235#post-390813797

  • 相关阅读:
    第二周作业
    第一次作业
    第0次作业
    第一次的作业
    第0次作业
    第三次作业
    %f使用时的注意事项
    关于c++停止工作
    第二次作业
    第一次作业
  • 原文地址:https://www.cnblogs.com/cyun/p/5581147.html
Copyright © 2020-2023  润新知