通过单击单选按钮禁用 - 启用超链接 [英] disable-enable a hyperlink by clicking on radio-buttons
问题描述
我有一个超链接代码,如:
点击这里
我希望根据我的单选按钮点击自定义此链接,如:
YES
NO
对应单选按钮值:'yes',我想启用超链接。
在单选按钮值时:'no',我想禁用超链接。
所以,为了在单击单选按钮'NO'后禁用超链接,我在disable-link()方法中写了以下内容:
function disable-link()
{
//document.getElementById('disable-link').disabled=true;
document.getElementById('disable-link')。href ='#';
}
现在,我必须在enable-link()方法中编写,以便在单击单选按钮'YES'后重新启用超链接
i have a hyperlink code like : Click Here and i want to customize this link on the basis of my radio button click,which are like : YES NO on radio-button value:'yes',i want to enable the hyperlink. while on radio-button value:'no',i want to disable the hyperlink. So,to make the hyperlink disable after clicking radio-button 'NO', i have written the following in disable-link() method : function disable-link() { //document.getElementById('disable-link').disabled=true; document.getElementById('disable-link').href = '#'; } Now,what i have to write in enable-link() method so that the hyperlink gets re-enabled after clicking radio-button 'YES'
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 ='#'; - :它使得链接也无法点击
请建议。
document.getElementById('disable-link').disabled=true*/*false; -: it makes the disable but user is able to click on the hyperlink though.So, i have used "document.getElementById('disable-link').href = '#';" -: it makes the link unclickable too Please suggest.
推荐答案
<!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>
这篇关于通过单击单选按钮禁用 - 启用超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!