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();
}
};
转载于:https://www.cnblogs.com/zwrblogs/p/6593485.html