js替换选中的文字


替换html中选中的文字

        function replaceSelection() {
            if (window.getSelection) {
                var selecter = window.getSelection();
                var selectStr = selecter.toString();
                if (selectStr.trim != "") {
                    var rang = selecter.getRangeAt(0);
                    var temp = $("<b>" + selectStr + "<b/>");
                    rang.surroundContents(temp[0]);
                }
            } else if (document.selection) {//ie
                var selecter = document.selection.createRange();
                selecter.select();
                var selectStr = selecter.text;
                selecter.pasteHTML("<b>" + selectStr + "<b/>");
            }
        }

  程序员的基础教程:菜鸟程序员


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM