如何通过单击第二个超链接禁用一个超链接

how to disable one hyperlink by clicking on second hyperlink

本文关键字:超链接 一个 何通过 单击 第二个      更新时间:2023-09-26

我有两个超链接。当我点击一个超链接时另一个超链接应该被禁用意味着它应该被看到但不能被任何用户点击

请帮帮我

 <a href="">hiii </a> 
 <a id="check" href="google.com">bye</a>
在JavaScript

$('#check').attr('disabled', true);

但是不工作

使用java脚本,您可以通过添加.disabled类来禁用超链接,如下所示:

  .inactive //add this class to the link if you want to disable it 
{
    pointer-events: none;// this will disable the link
    cursor:default;
}

Try below

$('.my-link').click(function () {return false;});

要重新启用它,请取消绑定处理程序:

$('.my-link').unbind('click');

$('.my-link').attr('disabled', 'disabled');

使用此命令重新启用:

$('.my-link').attr('disabled', '');

谢谢,湿婆

下面是您需要的代码。

<a id="gLink" href="http://google.com">click me</a><br />
<a onclick="disableLink()" href="#">Disable link</a><br />
<a onclick="enableLink()" href="#">Enable link</a>

javsacript功能:

 function disableLink() {
        var a = document.getElementById('gLink');
        a.href = "#";
    }
    function enableLink() {
        var a = document.getElementById('gLink');
        a.href = "http://google.com";
    }

例如:

  <a id="link1" href="page1.php">One</a> <a id="link2" href="page2.php">Two</a>
document.getElementById('link1').onclick = function()
 {
   document.getElementById('link1').disabled = true;
   document.getElementById('link2').disabled = false;
 };
  document.getElementById('link2').onclick = function()
 {
   document.getElementById('link1').disabled = false;
   document.getElementById('link2').disabled = true;
 };

我就知道这些

<html>
 <head>
 <script language="javascript" type="text/javascript">
  window.onload = firstLoad;
  function firstLoad() {
  document.getElementById("lesson").href = "";
   document.getElementById("posttest").href = "";
   }
     function clickHome() {
    document.getElementById("pretest").href = "";
     document.getElementById("lesson").href = "lesson.html";
    }
     function lessonRead() {
      document.getElementById("posttest").href = "posttest.html";
     document.getElementById("lesson").href = "";
       }
     </script>
         </head>
    <body>
      <a href="home.html" id="home" onClick="clickHome()">Home</a> | 
     <a href="pre-test.html" id="pretest">Pre-test</a> | 
     <a href="lesson.html" id="lesson">Lesson</a> | 
     <a href="post-test.html" id="posttest" onClick="lessonRead()">Post-test</a> | 
     <a href="about.html" id="about">About</a> | 
     </body>
     </html>

你可以使用jQuery的onClick事件(或。on("click")/.live("onClick")或任何你喜欢的)来改变链接的属性,像这样:

$('.my-link').attr('disabled', true);

短的例子:

<a href='#' id='link1'>First</a>
<a href='#' id='link2'>Second</a>
<script>
    $("#link2").onClick(function(){
        $('#link1').attr('disabled', true);
        };
    }
</script>

相关文章: