Why does clicking a drag handle NOT steal away text focus?

别等时光非礼了梦想. 提交于 2019-12-23 12:23:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!