How to enable or disable an anchor using jQuery?
相关问题
- Views base64 encoded blob in HTML with PHP
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
In css file
You never really specified how you wanted them disabled, or what would cause the disabling.
First, you want to figure out how to set the value to disabled, for that you would use JQuery's Attribute Functions, and have that function happen on an event, like a click, or the loading of the document.
Try the below lines
Coz, Even if you disable
<a>
taghref
will work so you must removehref
also.When you want enable try below lines
Selected Answer is not good.
Use pointer-events CSS style. (As Rashad Annara suggested)
See MDN https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events. Its supported in most browsers.
Simple adding "disabled" attribute to anchor will do the job if you have global CSS rule like following:
The app I'm currently working on does it with a CSS style in combination with javascript.
Then whenever I want to disable a link I call
Then, in the click handler for 'thelink' a tag I always run a check first thing
It's as simple as return false;
ex.
or