如何将div中选定的行突出显示为List [英] How to highlighted selected row in div as List

查看:43
本文介绍了如何将div中选定的行突出显示为List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个foreach循环在foreach下我有一个



tage在



标记一个输入复选框。在那个循环中他们是5项。并且



标签创建了5次。现在,当我检查假设第4项时,我想要仅突出显示红色的第4个



标签。如何实施?我附加了foreach循环代码。我使用MVC4。





I have one foreach loop under foreach I have one

tage under

tag one input checkbox. In that loop their is 5 items. And

tags created 5 times. Now when I check suppose 4th item then I want to highlighted only 4th

tag with red color. How to implement? I have attached foreach loop code. And I have use MVC4.




@foreach(ViewBag.LocationList中的SelectListItem项目) )

{



< input type =checkboxid =chkLocations

class =check/>


@foreach (SelectListItem item in ViewBag.LocationList)
{


<input type="checkbox" id="chkLocations"
class="check"/>

推荐答案





用分区包围你的输入标签并给出一个ID(id应该与你的复选框的ID相同,带有一些前缀)

例如如果您的复选框ID为1,则将您的Div ID设为DIV_1。



然后在复选框的点击事件上使用j查询首先检查天气,选中复选框或不基于该形式使用复选框ID形成Division ID并设置除法的背景颜色。


Surround your Input tag with a division and give a ID (id should be same as the ID of your check box with some prefix)
e.g. If your Check box id is 1 then make your Div id as DIV_1.

Then using j query on click event of the check box first check weather the check box is checked or not based on that form the Division id using check box ID and set the back ground color of the division.


使用Label和CSS获取相同的

as

use Label and CSS for achiving the same
as
@foreach (SelectListItem item in ViewBag.LocationList)
        {

        <input type="checkbox" id="_@item.key">
               class="check" />
        <label for="_@item.key">TAG</label>
        }





CSS:



CSS:

input[type=checkbox] + label {
            color: #ccc;
            font-style: italic;
        }

        input[type=checkbox]:checked + label {
            color: white;
            font-style: normal;
            background-color:red;
        }


这篇关于如何将div中选定的行突出显示为List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆