2012-11-01 110 views
0

我有这样一个超链接的代码: 点击这里 ,我想自定义单选按钮的点击,这是一样的基础上,此链接: 是的 否 在单选按钮值:'是',我想启用超链接。 而单选按钮值:'不',我想禁用超链接。因此,为了使超链接在单击单选按钮“否”后禁用,我在禁用链接()方法中写入了以下内容: function disable-link() { //document.getElementById('disable-链路')禁用=真。 document.getElementById('disable-link')。href ='#'; } 现在,我不得不写使能链()方法,这样的超级链接被点击单选按钮“YES”禁用启用超链接

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

的document.getElementById(“禁用链接”后重新启用).disabled = true */* false; - :它使禁用,但用户可以点击超链接虽然。因此,我已经使用“document.getElementById('禁用链接')。href ='#';” - :它使链接不可点击 请建议。

+1

发布您的网页代码 – polin

回答

5
<!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> 
+0

谢谢,它的工作..打了它.. :) – puneet2289