【问题标题】:disable-enable a hyperlink by clicking on radio-buttons通过单击单选按钮禁用-启用超链接
【发布时间】:2012-11-01 09:28:47
【问题描述】:

我有一个超链接代码,例如: 点击这里 我想根据我的单选按钮点击来自定义这个链接,就像: 是的 不 单选按钮值:'是',我想启用超链接。 在单选按钮值:'否'时,我想禁用超链接。 因此,为了在单击单选按钮“否”后禁用超链接,我在 disable-link() 方法中编写了以下内容: 功能禁用链接() { //document.getElementById('disable-link').disabled=true; document.getElementById('disable-link').href = '#'; } 现在,我必须在 enable-link() 方法中编写内容,以便在单击单选按钮“是”后重新启用超链接

function enable-link()
{
    //document.getElementById('disable-link').disabled=false;
        // SOME LINE OF CODE TO RE-ENABLE THE LINK
}

document.getElementById('disable-link').disabled=true*/*false; -: 禁用但用户可以点击虽然是超链接。所以,我使用了“document.getElementById('disable-link').href = '#';” -:它也使链接无法点击 请提出建议。

【问题讨论】:

    标签: javascript


    【解决方案1】:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>StackoverFlow answer for question</title>
    <script type="text/javascript">
    
        var link,color;
    
     function disable_link() { 
    
      document.getElementById('testlink').disabled=true;
    
      link = document.getElementById('testlink').href;
    
      document.getElementById('testlink').removeAttribute('href');
      //document.getElementById('testlink').style.color = "grey";
    
       } 
    
    
     function enable_link() { 
    
      document.getElementById('testlink').setAttribute("href",link);
    
       } 
    
    
    </script>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" onchange="disable_link();" />
          Radio</label>
        <br />
        <label>
          <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" onchange="enable_link();" />
          Radio</label>
        <br />
      </p>
      <a id="testlink" href="http://www.yahoo.com"> test </a>
    </form>
    </body>
    </html>
    

    【讨论】:

    • 谢谢,它的工作..明白了..:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    • 2011-08-19
    • 2013-05-19
    • 1970-01-01
    • 2013-07-09
    相关资源
    最近更新 更多