Javascript 如何在引导网格列中实现标记/全部标记?

Javascript 如何在引导网格列中实现标记/全部标记?,javascript,html,twitter-bootstrap,Javascript,Html,Twitter Bootstrap,在我的代码中,我需要这样的东西 对于网格,我使用了如下引导网格系统: <div class= "row"> <div class = "col-xs-06"></div> <div class = "col-xs-06"></div> <div class = "col-xs-06"></div> <div class = "col-xs-06"></div>

在我的代码中,我需要这样的东西

对于网格,我使用了如下引导网格系统:

<div class= "row">
    <div class = "col-xs-06"></div>
    <div class = "col-xs-06"></div>
    <div class = "col-xs-06"></div>
    <div class = "col-xs-06"></div>
</div>


现在点击一个按钮,我必须显示选择。如何做到这一点?

您应该使用css:after,如果您使用的是JQuery,那么这很容易做到

据我所知,当其中一个div单击时,您需要在其右上角显示一个标记(勾号)。因此,这是复选标记(tick)的代码,您可以在CSS
content
中使用它

HTML:

<div class="container">
<div class= "row our-div">
    <div class = "col-xs-6">div1</div>
    <div class = "col-xs-6">div2</div>
    <div class = "col-xs-6">div3</div>
    <div class = "col-xs-6">div4</div>
</div>
</div>
.active:after{
 font-family: "FontAwesome";
    content: "\2713";
    position: absolute;
    top: 5px;
    right: 5px;
    color: white;
    background:green;
    border-radius:25px;
    width:18px;
    height:18px;
    text-align:center;
}

.our-div > div{
  height:100px;
  background:purple;
   color:white;
}
$(".our-div div").click(function(){
  $(this).toggleClass('active');
});
JavaScript(JQuery):

<div class="container">
<div class= "row our-div">
    <div class = "col-xs-6">div1</div>
    <div class = "col-xs-6">div2</div>
    <div class = "col-xs-6">div3</div>
    <div class = "col-xs-6">div4</div>
</div>
</div>
.active:after{
 font-family: "FontAwesome";
    content: "\2713";
    position: absolute;
    top: 5px;
    right: 5px;
    color: white;
    background:green;
    border-radius:25px;
    width:18px;
    height:18px;
    text-align:center;
}

.our-div > div{
  height:100px;
  background:purple;
   color:white;
}
$(".our-div div").click(function(){
  $(this).toggleClass('active');
});

您应该使用css:after,如果您使用的是JQuery,那么这很容易做到

据我所知,当其中一个div单击时,您需要在其右上角显示一个标记(勾号)。因此,这是复选标记(tick)的代码,您可以在CSS
content
中使用它

HTML:

<div class="container">
<div class= "row our-div">
    <div class = "col-xs-6">div1</div>
    <div class = "col-xs-6">div2</div>
    <div class = "col-xs-6">div3</div>
    <div class = "col-xs-6">div4</div>
</div>
</div>
.active:after{
 font-family: "FontAwesome";
    content: "\2713";
    position: absolute;
    top: 5px;
    right: 5px;
    color: white;
    background:green;
    border-radius:25px;
    width:18px;
    height:18px;
    text-align:center;
}

.our-div > div{
  height:100px;
  background:purple;
   color:white;
}
$(".our-div div").click(function(){
  $(this).toggleClass('active');
});
JavaScript(JQuery):

<div class="container">
<div class= "row our-div">
    <div class = "col-xs-6">div1</div>
    <div class = "col-xs-6">div2</div>
    <div class = "col-xs-6">div3</div>
    <div class = "col-xs-6">div4</div>
</div>
</div>
.active:after{
 font-family: "FontAwesome";
    content: "\2713";
    position: absolute;
    top: 5px;
    right: 5px;
    color: white;
    background:green;
    border-radius:25px;
    width:18px;
    height:18px;
    text-align:center;
}

.our-div > div{
  height:100px;
  background:purple;
   color:white;
}
$(".our-div div").click(function(){
  $(this).toggleClass('active');
});

您可以单击“为每个类添加类”或“向所有类添加类”。标记

$(".className").click(function(){
    $(".className").addClass("mark");
});
要标记和取消标记,请使用
toggleClass()

参考资料:

<div class="container">
<div class= "row our-div">
    <div class = "col-xs-6">div1</div>
    <div class = "col-xs-6">div2</div>
    <div class = "col-xs-6">div3</div>
    <div class = "col-xs-6">div4</div>
</div>
</div>
.active:after{
 font-family: "FontAwesome";
    content: "\2713";
    position: absolute;
    top: 5px;
    right: 5px;
    color: white;
    background:green;
    border-radius:25px;
    width:18px;
    height:18px;
    text-align:center;
}

.our-div > div{
  height:100px;
  background:purple;
   color:white;
}
$(".our-div div").click(function(){
  $(this).toggleClass('active');
});
  • 您可以对每个类单击
    addClass()
    ,或将类添加到所有类。标记

    $(".className").click(function(){
        $(".className").addClass("mark");
    });
    
    要标记和取消标记,请使用
    toggleClass()

    参考资料:

    <div class="container">
    <div class= "row our-div">
        <div class = "col-xs-6">div1</div>
        <div class = "col-xs-6">div2</div>
        <div class = "col-xs-6">div3</div>
        <div class = "col-xs-6">div4</div>
    </div>
    </div>
    
    .active:after{
     font-family: "FontAwesome";
        content: "\2713";
        position: absolute;
        top: 5px;
        right: 5px;
        color: white;
        background:green;
        border-radius:25px;
        width:18px;
        height:18px;
        text-align:center;
    }
    
    .our-div > div{
      height:100px;
      background:purple;
       color:white;
    }
    
    $(".our-div div").click(function(){
      $(this).toggleClass('active');
    });
    

  • 您可以通过在之后添加一个带有
    :的类并设置该类的位置来完成此操作。那么JQery的addClass到目前为止你做了什么?@AjayMakwana和Kermani,我不知道怎么做?请帮助mecheck[this]()在那里尝试你的代码我必须使用Grid system@Don'tbenegative你可以通过在
    之后添加一个带有
    :的类并为其设置位置来完成。那么JQery的addClass到目前为止你做了什么?@AjayMakwana和Kermani,我不知道怎么做?请帮助mecheck[这个]()在那里尝试你的代码我必须使用Grid system@Don'tBenegative