zoukankan      html  css  js  c++  java
  • 利用foreach循环展示按钮(含在html中用三元运算符判断选择的内容给样式)

    这里 menuList是后台查询出来的数据然后用ViewBag返回给前台

    用三元运算给上css样式     @(menu.Reportid == reportid ? "class=condited" : "0") 

     @if (MenuList != null && MenuList.Count > 1)
                        {
                            <li>
                                <div class="close_operea clearfix">
                                    <p style="display: inline-block;font-size: 14px;height: 20px;line-height: 20px;color: #666;">统计类别</p>
                                </div>
                                <ol class="btn_close clearfix">
    
                                    @foreach (var menu in MenuList)
                                    {
                                        <li sval="@menu.Menuname" @(menu.Reportid == reportid ? "class=condited" : "0")  onclick="location.href = '/Menu/Index/?reportid=@menu.Reportid&menuid=@menu.Id'">@menu.Menuname</li>
                                    }
                                </ol>
                            </li>
                        }

    或者 加一个id 再在 js里用这样的方法也可以把当前操作的按钮赋上样式

     <li sval="@menu.Menuname"  id="button_@menu.Id"  onclick="location.href = '/Menu/Index/?reportid=@menu.Reportid&menuid=@menu.Id'">@menu.Menuname</li>

    <sprict>

    //var reportid = $("#hidReportid").val();
    //$("#button_" + reportid).css({ "border": "1px solid #008BFA","color":"#008BFA" });

    </sprict>

  • 相关阅读:
    函数的定义
    函数名的本质
    函数进阶
    三元运算
    数据类型 补充
    安装python问题
    neo4j nosql图数据库学习
    ubutun lunix 64安装neo4j 图形数据库
    git error: object file .git/objects/b9/e269f50db2a3415cc8ad5ba40b82b9b6a13d45 is empty
    django orm 时间处理
  • 原文地址:https://www.cnblogs.com/layla/p/8625603.html
Copyright © 2011-2022 走看看