admin管理员组

文章数量:1381492

I have a anchor tag which I would like to disable or enable depending upon some condition. I am able to achive this using the following function:

function disableEnableAnchor(obj, disable) {
    if(disable) {
        var href = obj.getAttribute("href");
        if(href && href != "" && href != null)
            obj.setAttribute('href_bak', href);
        obj.removeAttribute('href');        
    } else {
        var href_bak = obj.attributes['href_bak'].nodeValue;        
        obj.setAttribute('href', href_bak);
    }
}

But I am not able to remove the underline when the anchor is in a disabled state. How can I achieve this inside this function?

I have a anchor tag which I would like to disable or enable depending upon some condition. I am able to achive this using the following function:

function disableEnableAnchor(obj, disable) {
    if(disable) {
        var href = obj.getAttribute("href");
        if(href && href != "" && href != null)
            obj.setAttribute('href_bak', href);
        obj.removeAttribute('href');        
    } else {
        var href_bak = obj.attributes['href_bak'].nodeValue;        
        obj.setAttribute('href', href_bak);
    }
}

But I am not able to remove the underline when the anchor is in a disabled state. How can I achieve this inside this function?

Share Improve this question edited Jun 11, 2012 at 5:57 munity wiki
5 revs, 3 users 69%
vaibhav bindroo 0
Add a ment  | 

4 Answers 4

Reset to default 3
obj.style.textDecoration = "none"

You might want to consider replacing the anchor with a span.

This sounds like a stylesheet issue. Is there something like

a {
    text-decoration: underline;
}

in a CSS file that’s applied to the page?

Replacing it with the following CSS should make <a> tags only be underlined when they have an href attribute.

a:link,
a:visited,
a:hover,
a:active {
    text-decoration: underline;
}

Use this on HTML:

<a href="mylink" style="text-decoration

本文标签: Disable Anchor tag and remove underline also in javascriptStack Overflow