简体   繁体   English

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

[英]how to disable one hyperlink by clicking on second hyperlink

I have 2 hyperlinks. 我有2个超链接。 when i click on one hyperlink the another hyperlink should be disabled means it should be seen but not clicked by any user 当我点击一个超链接时,应该禁用另一个超链接意味着它应该被看到但不被任何用户点击

Please help me 请帮我

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

in JavaScript 在JavaScript中

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

but it is not working 但它不起作用

Using java script you can disable the hyper link by adding a .disabled class as seen below: 使用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;
}

then use .inactive class in appropriate line... 然后在适当的行中使用.inactive类...

Try below 试试以下

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

To re-enable it again, unbind the handler: 要再次重新启用它,请取消绑定处理程序:

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

or 要么

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

Use this to re-enable it: 使用它来重新启用它:

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

Thanks, 谢谢,

Siva 湿婆

Below is the code you need. 以下是您需要的代码。

<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 functions: javsacript函数:

 function disableLink() {
        var a = document.getElementById('gLink');
        a.href = "#";
    }

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

for eg if you have 例如,如果你有

  <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;
 };

You can use jQuery onClick event (or .on("click") / .live("onClick") or whatever you prefer) to change to attribute of the link like this: 您可以使用jQuery onClick事件(或.on(“click”)/ .live(“onClick”)或您喜欢的任何内容)来更改链接的属性,如下所示:

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

Short example: 简短的例子:

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

That's all I know 这是我所知道的一切

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM