【问题标题】:How to hide the anchor tag element rapidly on the onclick event using jQuery?如何使用jQuery在onclick事件上快速隐藏锚标记元素?
【发布时间】:2025-12-13 09:25:01
【问题描述】:

我有两个超链接。我在单击其他超链接时隐藏了一个超链接,反之亦然。它在我的本地机器上对我来说工作得非常好。但是,当我从在线服务器上传并运行相同的功能时,就会出现问题。

在服务器上,与本地计算机实例相比,相关超链接隐藏的速度并没有那么快。由于该用户可以再次单击他已经单击的超链接,并且该链接预计将被隐藏。隐藏相关的超链接需要一两个时间。我不想要那种延迟。超链接应在点击事件后立即隐藏。我尝试禁用/启用超链接,但对我来说不起作用。

我的代码如下:

<script language="javascript" type="text/javascript">
$(".fixed").click(function(e) { 
    var action_url1 = $(this).attr('delhref');
    var qid = $(this).data('q_id');


    $(".fixed").colorbox({inline:true, width:666});

    $("#fixedPop_url").off('click').on('click',function(event) {
      event.preventDefault();
      $.get(action_url1, function(data) {

        //$("#fix_"+qid).bind('click', false);
        $("#fix_"+qid).hide();//This portion of code I want to make fast, it's taking some time to hide and meanwhile user can click on this link. I want to avoid it.
        $("#notfix_"+qid).show();
        //$("#notfix_"+qid).bind('click', true);
        alert("Question status updated successfully");

      });      
    });       

    $(".c-btn").bind('click', function(){
      $.colorbox.close();
    });
  });

  $(".notfixed").click(function(e) { 
    var action_url2 = $(this).attr('delhref');
    var qid = $(this).data('q_id');

    $(".notfixed").colorbox({inline:true, width:666});

    $("#notfixedPop_url").off('click').on('click',function(event){
      event.preventDefault();
      $.get(action_url2, function(data) {

        //$("#notfix_"+qid).bind('click', false);
        $("#notfix_"+qid).hide();//This portion of code I want to make fast, it's taking some time to hide and meanwhile user can click on this link. I want to avoid it.
        $("#fix_"+qid).show();
        //$("#fix_"+qid).bind('click', true);
        alert("Question status updated successfully");

      });       
    });
</script> 

【问题讨论】:

    标签: javascript jquery html hyperlink show-hide


    【解决方案1】:

    您不必在get请求的完整功能中编写隐藏部分代码。在现场,获取 rspond 需要时间。所以只需将其放在get function.something 之外:

     $(".fixed").click(function(e) { 
        var action_url1 = $(this).attr('delhref');
        var qid = $(this).data('q_id');
        $("#fix_"+qid).hide();
        //rest code......
     });
     $(".notfixed").click(function(e) { 
        var action_url2 = $(this).attr('delhref');
        var qid = $(this).data('q_id');
        $("#notfix_"+qid).hide();//hide it here
        //rest code......
     });
    

    【讨论】: