使用javascript删除选择

pei*_*rix 4 javascript jquery

我正在使用具有可拖动滚动条的图像查看器.当用户拖动滚动条时,网页上的某些文本会被选中.我试过了

window.getSelection().removeAllRanges();
Run Code Online (Sandbox Code Playgroud)

但这似乎不适用于IE7/8.也试过了

document.getSelection().removeAllRanges();
Run Code Online (Sandbox Code Playgroud)

这似乎与IE7/8一样"好".

有没有其他方法可以做到这一点?不知道任何jQuery解决方案,但如果有,请告诉我(:

编辑:这是onmouse事件的上下文

$("#slideBar").mousedown(function(f) {
    mouseDown = true;
    some more code...
}

$(document).mouseup(function() {
    if (mouseDown) {
       window.getSelection().removeAllRanges();
       more code...
    }
}
Run Code Online (Sandbox Code Playgroud)

BYK*_*BYK 6

尝试在您使用的函数上返回false,尤其是对于"mousedown"事件.在document.onselectstart和document.ondragstart上返回false也会有所帮助.