Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 具有Openlayers的Body缺少鼠标向下事件_Jquery_Dom_Openlayers_Jquery Events - Fatal编程技术网

Jquery 具有Openlayers的Body缺少鼠标向下事件

Jquery 具有Openlayers的Body缺少鼠标向下事件,jquery,dom,openlayers,jquery-events,Jquery,Dom,Openlayers,Jquery Events,我使用jQuery的.bind()函数向添加了一个mousedown事件,如下代码所示: $('body').bind('mousedown', function(){alert(1)}); 它在页面上的其他任何位置都能完美工作。但它将被(???)一个“地图”分区阻止。 (我不知道这个词是否精确到可以说“被阻挡”,这个词是不是随我的感觉而来) 函数.mousedown()也不起作用: $('body').mousedown(function(){alert(1)}); 以下是使用OpenLa

我使用jQuery的
.bind()
函数向
添加了一个
mousedown
事件,如下代码所示:

$('body').bind('mousedown', function(){alert(1)});
它在页面上的其他任何位置都能完美工作。但它将被(???)一个“地图”分区阻止。 (我不知道这个词是否精确到可以说“被阻挡”,这个词是不是随我的感觉而来)

函数
.mousedown()
也不起作用:

$('body').mousedown(function(){alert(1)});
以下是使用OpenLayers的map div:

<script type='text/javascript'>
var map;
function init() {
    var controls_array = [
        new OpenLayers.Control.Navigation({}),
        new OpenLayers.Control.PanZoomBar({}),
        new OpenLayers.Control.LayerSwitcher(),
    ];
    var mapOptions = {
        controls: controls_array,
        projection: new OpenLayers.Projection("EPSG:900913")
    };
    map = new OpenLayers.Map('map', mapOptions);

    var googleLayer = new OpenLayers.Layer.Google(
        'Google Map Layer',
        {
            numZoomLevels: 20,
            isBaseLayer: true,
            sphericalMercator: true,
            projection: "EPSG:900913"
        }
    );
    map.addLayer(googleLayer);
    map.zoomToExtent(
        new OpenLayers.Bounds(3235795.723665,493480.6015713,
        3716431.757455,911132.5240634), true
    );
}
</script>
<body onload='init();'>
    <div id="map" style='width: 800px; height: 700px;'></div>
</body>
我猜这是因为
OpenLayers.Controls.DragPan()
函数对
mousedown
事件作出反应


那么我该怎么做来修复它呢?让事件传递到

OpenLayers有自己的eventListener,因此您需要覆盖它们,例如

map.events.listeners.mousedown.unshift({ 
    func: function(){
        alert('hola muheres');
    }
});

签入
OpenLayers.Controls.DragPan()
函数,如果其中有
.preventdefault
.stopPropagation
行,将其删除,然后测试感谢您的提醒,我看到了
OpenLayers.Event.preventdefault(evt)
OpenLayers.Handler.Drag
中拖动
dragstart
以防止文档拖动,但似乎我不应该删除它。还有别的办法吗?
map.events.listeners.mousedown.unshift({ 
    func: function(){
        alert('hola muheres');
    }
});