如何通过Javascript禁用基于条件的超链接 [英] How to disable the hyperlink based on the condition through Javascript
本文介绍了如何通过Javascript禁用基于条件的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何禁用基于条件的超链接
$ p $ var mydiv = document.getElementById(myDiv);
var aTag = document.createElement('a');
Tag.setAttribute('href',yourlink.htm);
aTag.innerHTML =link text;
mydiv.innerHTML =;
mydiv.innerHTML = aTag;
说我需要在这里禁用我的aTag。
基于登录用户,我需要禁用或启用..
解决方案
这应该可以工作
if(condition)
disableLink();
else
showLink();
function disableLink()
{
document.getElementById('Link1')。disabled = true;
document.getElementById('Link1')。removeAttribute('href');
document.getElementById('Link1')。style.textDecoration ='none';
document.getElementById('Link1')。style.cursor ='default';
}
函数showLink()
{
document.getElementById('Link1')。disabled = false;
//动态分配href
document.getElementById('Link1')。href =somepage.html;
document.getElementById(Link1)。style.textDecoration =underline;
document.getElementById(Link1)。style.cursor =hand;
}
How to disable the hyperlink based on the condition
var mydiv = document.getElementById("myDiv");
var aTag = document.createElement('a');
aTag.setAttribute('href',"yourlink.htm");
aTag.innerHTML = "link text";
mydiv.innerHTML="";
mydiv.innerHTML=aTag;
say i need to disable my aTag here.
Based on logged on user i need to disable or enable..
解决方案
This should work
if(condition)
disableLink();
else
showLink();
function disableLink()
{
document.getElementById('Link1').disabled=true;
document.getElementById('Link1').removeAttribute('href');
document.getElementById('Link1').style.textDecoration = 'none';
document.getElementById('Link1').style.cursor = 'default';
}
function showLink()
{
document.getElementById('Link1').disabled=false;
//assign href dynamically
document.getElementById('Link1').href = "somepage.html";
document.getElementById("Link1").style.textDecoration = "underline";
document.getElementById("Link1").style.cursor = "hand";
}
这篇关于如何通过Javascript禁用基于条件的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文