Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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禁用锚定标记_Jquery_Image_Anchor - Fatal编程技术网

使用Jquery禁用锚定标记

使用Jquery禁用锚定标记,jquery,image,anchor,Jquery,Image,Anchor,我有一个与锚定标记相关联的图像,一旦用户单击该图像,就会加载一个弹出窗口。我想禁用此锚定标记 html代码如下所示: <a href="#" class="openModalLink"> <img style="vertical-align: middle; border: none" width="9%" alt="" id="imgmap" class="zoom" /></a> 感谢您的回复您可以这样做 $('.openModalLink').clic

我有一个与锚定标记相关联的图像,一旦用户单击该图像,就会加载一个弹出窗口。我想禁用此锚定标记

html代码如下所示:

<a href="#" class="openModalLink">
<img style="vertical-align: middle; border: none" width="9%" alt="" id="imgmap" class="zoom" /></a>
感谢您的回复

您可以这样做

$('.openModalLink').click(function(event){
    event.preventDefault();
});
也指

编辑:

启用和禁用锚定标记的步骤

function disabler(event) {
    event.preventDefault();
    return false;
}

$('#enable').click(function(){
    $('.openModalLink').unbind('click',disabler);
});
$('#disable').click(function(){
    $('.openModalLink').bind('click',disabler);
});
​

编辑2:

从jquery 1.7开始,
.on()
.off()
优先于绑定和取消绑定,以附加和删除元素上的事件处理程序

$('#enable').click(function() {
    $('body').off('click', '.openModalLink', disabler);
});
$('#disable').click(function() {
    $('body').on('click', '.openModalLink', disabler);
});​
:)这个问题被问了很多次布鲁夫:见副本:
$('#enable').click(function() {
    $('body').off('click', '.openModalLink', disabler);
});
$('#disable').click(function() {
    $('body').on('click', '.openModalLink', disabler);
});​