How to enable / disable link in javascript?

I have a link button on the page.

<asp:LinkButton ID="edit" runat="server" OnClick="edit_Click" Enabled="False">ویرایش</asp:LinkButton>

I want to enable / disable this in javascript.

I use this code but set visible

var objedit = document.getElementById('<%= edit.ClientID.ToString() %>');
objedit.style.display = "none";

I use this code but not include

if (count == 1) {
    objedit.disabled = false;
} else {
    objedit.disabled = true;
}

I can click, but linkbutton is disabled.

enter image description here

+5
source share
5 answers

try it

var objedit = document.getElementById("edit"); //not editid (editid is a variable)
objedit.disabled = true; //if I'm not mistaken its true/false or disabled
0
source

So, is that what you want? - UPDATED, tested in Chrome and Firefox
http://jsfiddle.net/hzaR6/
http://jsfiddle.net/hzaR6/2/

INDICATED method

You can use the name classto identify a disabled item for which you can have more control over your styles ... etc.

$("#link").toggleClass("disabled"); //This will simply toggle the class

and for css

#link.disabled{
    z-index:-1;            /*Make it not clickable*/
    position:relative;
    opacity: .5;           /*Lighter*/
}​

You can do whatever you want here.

Good old way form

$("#edit").attr("disabled", false);
 -or-
document.getElementBy("edit").disabled = false;

. , false true.


var a = document.getElementBy("edit").disabled;

a true, . false.

0

, . "" , javascript. , , void false.

script:

<script runat="server">
   var a = document.getElementById('<%= edit.ClientID.ToString() %>')
</script>
0
document.getElementById("lnk").style.display = "none";
0

:

document.getElementById('<%# edit.ClientID %>').disabled = 'disabled';
//.ToString() is not necessary; ClientID is a string.

:

document.getElementById('<%# edit.ClientID %>').disabled = '';

, (DOM).

0

All Articles