单击链接后,使链接无法点击 - jquery [英] Make a link unclickable once it has been clicked - jquery

查看:80
本文介绍了单击链接后,使链接无法点击 - jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在点击链接后使其无法点击,然后在点击其他链接后再点击。基本上只是一个切换但我需要使活动链接不可点击以防止切换。这是我的代码:

I am trying to make a link unclickable once it is clicked, then clickable once another link is clicked. Basically just a toggle but I need to make the active link unclickable to prevent the toggle. Here is my code:

$(document).ready(function(){
       $("#Espanol").hide();
       $("#espLink").addClass("nonSelected");           
       // Make english link unclickable
       $("#espLink").click(function(){
           $("#engLink").addClass("nonSelected");
           $("#espLink").removeClass("nonSelected");
           $("#English").toggle(); 
           $("#Espanol").toggle();    
           // need to make espanol link unclickable  
           // and english link clickable             
       });

       $("#engLink").click(function(){
           $("#espLink").addClass("nonSelected");
           $("#engLink").removeClass("nonSelected");
           $("#English").toggle(); 
           $("#Espanol").toggle();  
           // need to make english link unclickable  
           // and espanol link clickable        
       });
    });

和html:

<a id="engLink">English</a> | <a id="espLink">Español</a>

有谁知道怎么做?

推荐答案

在click函数中添加一个测试,以查看该链接是否具有正确的nonSelected类。如果没有,点击就没有任何反应。

Add a test in the click function to see if the link has the right 'nonSelected' class. If it doesn't, nothing happens on click.

$(document).ready(function(){
   $("#Espanol").hide();
   $("#espLink").addClass("nonSelected");           
   // Make english link unclickable
   $("#espLink").click(function(){
       if($(this).hasClass('nonSelected')){
           $("#engLink").addClass("nonSelected");
           $("#espLink").removeClass("nonSelected");
           $("#English").toggle(); 
           $("#Espanol").toggle();    
           // need to make espanol link unclickable  
           // and english link clickable    
       }else{
           return false;
       }         
   });

   $("#engLink").click(function(){
       if($(this).hasClass('nonSelected')){
           $("#espLink").addClass("nonSelected");
           $("#engLink").removeClass("nonSelected");
           $("#English").toggle(); 
           $("#Espanol").toggle();  
           // need to make english link unclickable  
           // and espanol link clickable 
       }else{
           return false;
       }                
   });
});

这篇关于单击链接后,使链接无法点击 - jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆