如何取消选择所有非输入字段的元素

Posted

技术标签:

【中文标题】如何取消选择所有非输入字段的元素【英文标题】:How to unselect all elements which are Not input fields 【发布时间】:2011-11-16 02:15:27 【问题描述】:

我的页面上有很多大图像,当用户将光标拖到它们上面时,选中的蓝色突出显示会使图像变暗并且不会轻易消失。如何使用this plugin(noselect jquery-plugin)

$.fn.noSelect = function()
        var none = 'none';
        return this.bind('selectstart dragstart mousedown', function() 
                return false;
        ).css(
                'MozUserSelect': none,
                'WebkitUserSelect': none,
                'userSelect': none
        );
;

找到被选中的元素并取消选中它们,除了表单、文本区域和输入字段需要被选中才能起作用。

也许涉及@ 987654324 jQuery selector?

非常感谢!

【问题讨论】:

【参考方案1】:

:selected 选择器用于选择语句,即。列表/选项。

您为什么不将适当的 CSS 添加到您不想选择的图像中? 如果您正在监听某些拖动事件,只需在拖动开始时将其应用于所有图像。

var isDragging = false;
$(document).ready(function()
        $("img").noSelect();
        //or
        $(document).mousedown(function()
             isDragging = true;
             $("img").noSelect();
        ).mouseup(function()
             isDragging = false;
             $("img").makeSelectable();
        );
);

【讨论】:

以上是关于如何取消选择所有非输入字段的元素的主要内容,如果未能解决你的问题,请参考以下文章