简体   繁体   English

使用JQuery禁用文本输入的拖动滚动

[英]Disabling Drag Scroll for Text Inputs with JQuery

I need to disable the drag scroll functionality when clicking on text inputs. 单击文本输入时,我需要禁用拖动滚动功能。 The page is in the format of a table of a div with inputs inside, and you can drag the page horizontally when you click and drag anywhere. 该页面的格式为带有内部输入的div表格,您可以在单击并拖动到任何位置时将其水平拖动。 I want to make this so you can only drag when you don't click on one of the inputs, and disable the drag when an input is clicked so the input can be edited. 我要这样做,以便仅在不单击输入之一时才可以拖动,而在单击输入时禁用拖动,以便可以编辑输入。 Here is my go at it: 这是我的努力:

$('.dataContent').mousedown( function (event) { 
        if($(this).children().size()>0) {$(this)
        .data('down', true)
        .data('x', event.clientX)
        .data('scrollLeft', this.scrollLeft);

        return false;
        }

You can use event.target to obtain the element that was the event's original target: 您可以使用event.target获取作为事件原始目标的元素:

$('.dataContent').mousedown(function(event) {
    if ($(event.target).is("input:text")) {
        return;  // Target element is a text input, do not initiate drag.
    }

    // ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM