首页 > 代码库 > 鼠标选中 并 设置其颜色

鼠标选中 并 设置其颜色

var Btn = document.getElementById("unmark");
var oBtn = document.getElementById("mark");
oBtn.onclick = function() {
var range, sel;
var colour = ‘yellow‘;
var itemlen = $(‘#data_que‘).find(‘#question‘).length;
var item = $(‘#data_que‘);
if (window.getSelection) {
// IE9 and non-IE
try {
if (!document.execCommand("BackColor", false, colour)) {
makeEditableAndHighlight(colour);
}
} catch (ex) {
makeEditableAndHighlight(colour);
}
} else if (document.selection && document.selection.createRange) {
// IE <= 8 case
range = document.selection.createRange();
range.execCommand("BackColor", false, colour);
}
//$("#text_area").text(text);
if(itemlen == 0){
//window.getSelection().removeAllRanges();
clearSelection();
}
};
//取消标记
Btn.onclick = function() {
var range, sel;
var colour = ‘#fff‘;
var itemlen = $(‘#data_que‘).find(‘#question‘).length;
var item = $(‘#data_que‘);
if (window.getSelection) {
// IE9 and non-IE
try {
if (!document.execCommand("BackColor", false, colour)) {
makeEditableAndHighlight(colour);
}
} catch (ex) {
makeEditableAndHighlight(colour);
}
} else if (document.selection && document.selection.createRange) {
// IE <= 8 case

range = document.selection.createRange();
range.execCommand("BackColor", false, colour);
}
//$("#text_area").text(text);
if(itemlen == 0){
//window.getSelection().removeAllRanges();
clearSelection();
}
};

鼠标选中 并 设置其颜色