jquery - 禁用 jquery 中 anchor 上的 .click 功能

标签 jquery onclick anchor attr

这是用 jquery 在外部 .js 中编写的...

我有两个窗口可以滑入和滑出 View ,例如:

$(document).ready(function() {
  // hides gallery1 as soon as the DOM is ready  
  $('#gallery1').hide();  
  // shows the menu on click   
  $('#showgal1').click(function() {  
    $('#gallery1').delay(490).show('slide', {direction:'left'});
    $('#gallery2').hide('slide', {direction:'right'});
    //need code to disable showgal1 and enable showgal2
  });
  $('#showgal2').click(function() {  
    $('#gallery2').delay(490).show('slide', {direction:'right'});
    $('#gallery1').hide('slide', {direction:'left'});
    //need code to disable showgal2 and enable showgal1
  });
});

“gallery1”和“gallery2”是带有 Flash 图像画廊的 DIV,“showgal1”和“showgal2”是 anchor 的 ID...

看起来像

<a href="#" id="showgal1">gallery 1</a>

我找不到一种方法来在单击一个功能时禁用 .click 功能并重新启用另一个功能...

我想默认禁用“showgal1”,当“showgal2”事件发生时,它会删除该属性并禁用“showgal2”,直到单击“showgal1”为止...

.attr('disabled','disabled') 尚未工作...

最佳答案

如果关联的图库已经​​可见,您想在单击 showgal 时停止任何操作吗?

$('#showgal1').click(function(){
    if($('#gallery1').is(":visible"))
       return false;

    $('#gallery1').delay(490).show('slide', {direction:'right'});
    $('#gallery2').hide('slide', {direction:'left'});

});

$('#showgal2').click(function(){
    if($('#gallery2').is(":visible"))
       return false;
    $('#gallery2').delay(490).show('slide', {direction:'right'});
    $('#gallery1').hide('slide', {direction:'left'});

});

如果相应的图库已经​​可见,每个click函数的前两行将停止该函数。

关于jquery - 禁用 jquery 中 anchor 上的 .click 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4531917/

相关文章:

javascript - 按钮 onclick 打开 WordPress 短代码

javascript - 调用其他标签的onclick事件

javascript - PDF 中的 anchor 标记在 firefox 和 safari 中不可点击

javascript - 转到单击事件 jquery 上的 anchor 链接

javascript - 未捕获的类型错误 : Cannot read property 'row' of undefined - google visualisation api

javascript - 将 onclick 添加到来自 javascript 的标签

jquery - 如何将 div 放在不同的图层上?

html - CSS anchor 悬停图像过渡

javascript - 如何访问嵌套的 json 对象并使用 javascript 动态显示?

javascript - 为什么 Angular `ng-repeat` 有不同的复选框区分行为然后手动列出复选框?