jq根据后端返回的对象值来控制权限显示的方法

2021-07-09 11:11:16 浏览数 (2)

jq根据后端返回的对象值来控制权限显示的方法

代码语言:javascript复制
<!doctype html>
<html class="no-js" lang="">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1">
    <title>权限显示控制方法</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes"/>
    <meta name="author" content="liweiliang">
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache">
</head>
<body>      
    <style>
       .permit_items{display: none;float:left; width: 50px; height: 30px; line-height: 30px; text-align: center; margin:5px; border:1px solid red;}
   </style>
   <p>Hello world! </p>
   <div class="permit_items" permit="sales">查看</div>
   <div class="permit_items" permit="sales_add">添加</div>
   <div class="permit_items" permit="sales_del">删除</div>
   <div class="permit_items" permit="sales_edit">编辑</div>
   <div class="permit_items" permit="sales_publish">上下架</div>
   <div class="permit_items" permit="artical">文章</div>
   <div class="permit_items" permit="role">角色</div>
   <div class="permit_items" permit="user">用户</div>
   <script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
   <script>
      $(function(){
            var objpremit = {"sales_add":true,"sales_del":true,"sales_publish":true,"user":true};
            $("[permit]").each(function(k,v){
                j = $(v).attr("permit");
                if(objpremit[j]){
                    $(v).show();
                    console.log("show");
                }else{
                    $(v).hide();
                }
            });
    })
</script>
</body>
</html>

0 人点赞