简体   繁体   English

如何显示和隐藏 <li> 面板内?

[英]How can show and hide a <li> inside the panel?

I have an app that has a login page. 我有一个具有登录页面的应用程序。 In order to login the user has the permission to see two voice inside the panel (if user is admin). 为了登录,用户有权在面板内看到两个声音(如果用户是admin)。 If user is not admin I'd like to not display this voices. 如果用户不是管理员,我不想显示此声音。 My problem is how to hide and show its. 我的问题是如何隐藏和显示它。 I have the panel inside index.html.This are the voice that I'd like to display or not in order users permission. 我在index.html中有面板。这是我想显示或不显示的声音,以便获得用户的许可。

            <li id="company" display="none">
                    <a href="/aziende/" class="panel-close" >
                        <div class="item-content">
                            <div class="item-media">
                                <i class="f7-icons ios-only">home</i>
                                <i class="material-icons md-only">home</i>
                            </div>
                            <div class="item-inner">
                                <div class="item-title">Company</div>
                            </div>
                        </div>
                    </a>    
                </li>

                <li id="users" display="none">
                    <a href="/users/" class="panel-close">
                        <div class="item-content">
                            <div class="item-media">
                                <i class="f7-icons ios-only">person</i>
                                <i class="material-icons md-only">account_circle</i>
                            </div>
                            <div class="item-inner">
                                <div class="item-title">Users</div>
                            </div>
                        </div>
                    </a>
                </li>

this is app.js 这是app.js

     {
        name: 'login',
        path: '/login/',
        url: './pages/login.html',
        on:{ 
                pageInit: function(){

                    app.navbar.hide('.navbar');
                    if(user.checkPermission() == 'true'){
                        app.router.navigate('/home/');

                        }
                    }
            },
    },
    {
        name: 'home',
        path: '/home/',
        url: './pages/home.html',
        on: {
            pageInit:   function(e, page) {

                            app.navbar.show('.navbar');
                             if(user.checkPermission() == 'true'){
                                addVoicesToNavbar();

                             }
                            }                                   
                            page.router.clearPreviousHistory();
                        }

        },
    }

this method said me that Cannot set property 'display' of null 这个方法说我不能设置null的属性'display'

  function addVoicesToNavbar(){
      document.getElementById("company").display = "block";
      document.getElementById("users").display = "block";

   }

display is not a valid html attribute, it is a CSS property. display不是有效的html属性,它是CSS属性。

So setting display="none" on your <li> in the example doesn't do anything. 因此,在示例中的<li>上设置display="none"不会执行任何操作。

Instead in your markup you need to set an inline CSS style like this to initially hide the element: 相反,您需要在标记中设置一个这样的内联CSS样式,以最初隐藏该元素:

<li id="users" style="display:none;">

And in your function change that inline CSS style like this to show it: 然后在您的函数中更改内联CSS样式,如下所示:

document.getElementById("users").style.display = "block";

Here is an example of what you could do: 这是您可以做什么的示例:

 function addVoicesToNavbar(){
      companyElement = document.getElementById("company");
      companyElement.style.display = "block";

      ...
   }

Hope it helps! 希望能帮助到你!

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

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