鼠标选中 并 设置其颜色
Posted ~噜啦啦~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鼠标选中 并 设置其颜色相关的知识,希望对你有一定的参考价值。
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();
}
};
以上是关于鼠标选中 并 设置其颜色的主要内容,如果未能解决你的问题,请参考以下文章