问题
I have a div with some text at http://jsfiddle.net/MuCeD/2/. If I double-click the word "sample" in the div it becomes highlighted and if I then click anywhere else on the page the text becomes un-highlighted - except if I click on the blue drag handle of the second box. Then "sampled" remains highlighted.
If you remove the handle specification, as below,
$('#box').draggable();
so you can drag from anywhere on the left box, then you can click anywhere in that box without losing the text focus.
Does anyone understand what's going on here? What does the drag handle do to keep from stealing the focus?
Thanks
回答1:
The jQuery UI draggable cancels its mousedown event. This is why it doesn't receive focus and thus doesn't steal other elements' focus. You can use the following example outside of the draggable context.
HTML:
<a href="#">Some link</a>
<a class="not-focusable" href="#">No focus</a>
JavaScript:
$('.not-focusable').mousedown(function (event) {
return false;
});
JSFiddle
来源:https://stackoverflow.com/questions/16916711/why-does-clicking-a-drag-handle-not-steal-away-text-focus