简体   繁体   中英

How to get the value of that input text?

I have two roles "admin" and "student", if the role = "student" I want to hide the admin menu

Html

<input id="role" value='<?php echo $_SESSION[$config["session"]]["role"];?>'>

Javascript

function loadPage(){
   if($("#role").val() == "student"){
       $("#admin-menu").hide()
   }
}

Call your function after document load.

$(document).ready(function() {
loadPage();
});

You could add this to your menu container class

<?= ($_SESSION[$config["session"]]["role"]?= admin: 'hidden'? '') ?>

It would add class 'hidden' if the user's role is not admin

But the better practice is to use separate views for different user roles or|and do not render admin menu at all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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