1个回答
展开全部
要做一个功能就是在一个div中选中一段文字,然后把选中的加个背景。
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
}else if (document.getSelection) {
return document.getSelection();
}else if (document.selection) {
return document.selection.createRange().text;
}
}
function Test(){
var t=getSelectedText();
if(t.length>0){
var content=document.getElementById('repFirstpage').innerHTML;
__global_notes__count++;
content=content.replace(t,"<span style='background-color:#ff0000'><strong>["+__global_notes__count+"]</strong>"+t+"</span>"); document.getElementById('repFirstpage').innerHTML=content;
$('#divNotes').show(100);
$("#txtNotes").select();
}
}
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
}else if (document.getSelection) {
return document.getSelection();
}else if (document.selection) {
return document.selection.createRange().text;
}
}
function Test(){
var t=getSelectedText();
if(t.length>0){
var content=document.getElementById('repFirstpage').innerHTML;
__global_notes__count++;
content=content.replace(t,"<span style='background-color:#ff0000'><strong>["+__global_notes__count+"]</strong>"+t+"</span>"); document.getElementById('repFirstpage').innerHTML=content;
$('#divNotes').show(100);
$("#txtNotes").select();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询