码迷,mamicode.com
首页 > 其他好文 > 详细

鼠标选中 并 设置其颜色

时间:2017-03-21 12:48:11      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:exe   create   get   .text   back   clear   remove   设置   ntb   

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();
}
};

鼠标选中 并 设置其颜色

标签:exe   create   get   .text   back   clear   remove   设置   ntb   

原文地址:http://www.cnblogs.com/zwrblogs/p/6593485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!