Need help with javascript disabling / enabling
<script type="text/javascript">
links_disabled = false;
$('a').click(function(e){
links_disabled = (links_disabled ? false : true);
});
</script>
My link:
<a href="/board/take_turn?id=131&x=0&y=2" data-remote="true" onclick="return links_disabled;">
<div class=开发者_JAVA百科"ttt_square">
</div>
</a>
What I want to do is when I click a link like the one above, I want it to disable the rest of the links. Am I on the right track?
Apart from putting a <div>
inside an <a>
, yes: it looks like you're on the right track.
Of course, you are swapping the links_disabled
when links are clicked, which might not do what you want…
// initialize to false
var links_disabled = false;
// bind to a link click
$('a').click(function(){
// reverse the value of the disabled variable
links_disabled = !links_disabled;
// return the result (no need for it to go in markup as
// jQuery is already handling this)
return links_disabled;
});
then the HTML
<!-- no longer need for onClick, jQuery is already binding to this event -->
<a href="/link/to/file">Some Link</a>
Try this:
http://jsfiddle.net/seamusjr/X7Y9w/3/embedded/result/
Basically I put the links in a nav element so they are siblings.
When I click on one it removes the disabled attr and className from itself and applies it to its sibling links.
精彩评论