简体   繁体   English

如何根据复选框的值在侧边栏菜单上隐藏和显示特定链接?

[英]How to hide and show a particular link on a sidebar menu based on checkbox value?

Is it possible to hide and show a link/icon on a sidebar menu based on checkbox value? 是否可以根据复选框的值在侧边栏菜单上隐藏和显示链接/图标?

I have a checkbox that once enabled (value = on), the icon of that particular link on sidebar menu should be shown and once disabled will be hidden. 我有一个复选框,一旦启用此复选框(值= on),则应在侧边栏菜单上显示该特定链接的图标,而一旦禁用则将被隐藏。

Hope someone could help me. 希望有人可以帮助我。 Thanks! 谢谢!

file.html file.html

{% elif field.type == 'checkbox' %} 
<div class="form-group"> 
<label>{{ field.prompt }}</label> 
<br> 
<input type="{{ field.type }}" class="form-control {{ field.name }}" name="{{ field.name }}"> 
</div>


$form_admin_config.validate({ 
ignore: 'input[type=hidden], .ignore', 
onkeyup: false, submitHandler: 
function(form) { 
$form_admin_config.find('input[type="checkbox"]').each( function () {
         var checkbox_this = $(this);

         if( checkbox_this.is(":checked") == true ) {
             checkbox_this.attr('value', 'on');    
         } else {
             checkbox_this.prop('checked',true);
             checkbox_this.attr('value', '');

             }
             })
             ajax_post_form($form_admin_config, 'Save Successful', function(){
             },
             function() {});
             }

        });

base.html base.html文件

<li class="{% if request.mod == 'subscription_products' %}inactive{% endif %} main_menu" data-toggle="popover" data-content="Subscription Products">
<a href="{% url 'admin_app:subscription_products_index' %}" ><i class="fa fa-check-square-o"></i> <span class="nav-label"> Subscription Products </span></a></li>
{% endif %}

file.py file.py

def admin_config_process(request):
    for key, val in request.POST.iteritems():
        if key != 'csrfmiddlewaretoken':
            admin_config = AdminConfig.getAdminConfigFromName(key)
            if admin_config is not None:
                admin_config.svalue = val
                admin_config.save()
            else:
                new_id = make_uuid()
                admin_config = AdminConfig.getAdminConfig(new_id)
                if radmin_config is not None:
                    new_id = make_uuid()
                AdminConfig(new_id, None, key, val).save()

    return jsonify({'status': 'ok'})

Try something like this: 尝试这样的事情:

 $('#chk').click(function(){ if( $(this).is(':checked') ) { $('#link1').show(); } else { $('#link1').hide(); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" value="1" id="chk" />Check <ul> <li id="link1">Link 1</li> </ul> 

You can get the checkbox value like: 您可以使用以下复选框值:

$(this).val(); but this will give the same value doesn't matter whether the checkbox is checked or not. 但这将提供相同的值,不管是否选中该复选框。 So you have to put the logic to get the value of checkbox only when it is checked. 因此,仅当复选框被选中时,您才需要使用逻辑来获取复选框的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM