开发者

Hiding buttons via Javascript

I have a small problem that I am hoping you guys can help me with. I have two buttons that I use to approve, or disable rates. Basically, makes the boolean flag True or False. Now I'm having some trouble wrapping my head around this idea but, I would like to have only the Approve button show if rates are disabled, and vice versa for the Disable button.

Anyone have any suggestions to get m开发者_运维技巧e started?

Thanks so much.

Steve


your question is really not enough specific. If you want to hide button via css you add property

 display: hidden;

if you want to toggle buttons after clicking one, you can write jquery code as following:

 $('#approveButton').click(function(){
  $('#disableButton').show();
  $(this).hide();
)};
 $('#displayButton').click(function(){
  $('#approveButton').show();
  $(this).hide();
)};


You have two choices - hide & show the buttons server side with django or do it client side with javascript (as the other answers mention).

Either way, you first add the approved boolean to the Rate model - I'm guessing you know how to do that.

In a django template, you can use an if statement to check the approved boolean and show the results:

{% if approved %}<button disableRate>{% else %}<button approveRate>{% endif %}

You should look at ajax though, because otherwise you'll be doing an entire page load every time you click one of those buttons

http://www.nomadjourney.com/2009/01/using-django-templates-with-jquery-ajax/

http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/ (old)


Mess with the css:

$('aproveButton').setStyle('display','none');
$('disableButton').setStyle('display','block');

Initialize your gui bit with only one button displayed, then onClick do whatever functionality you have to do and switch the visibility around.


Or you could use the django template tags to selectively show the buttons based on the state of your python variable(s):

{% if approved == True %}
    ((disable button HTML))
{% else %}
    ((approve button HTML))
{% endif %}

Of course, for this to work, you will have to pass the python variable from your views.py file to the template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜