替换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/>"); } }
时间: 2024-11-04 12:41:07