javascript - 多个类的选择不起作用

标签 javascript jquery html css angularjs

这是我的JS

$('.normal-box').click(function(){
    //unique row id
   var id = $(this).data('row-id');
   //its index according to the content array
   var index = $(this).data('index');
   //which card does this row belong to
   var card_name = $(this).data('id');
   var card;
   console.log(id) //el id de noten es de por si "link last_updated" concatenado
   switch(card_name){
       case "noten" : card = Unidos.CardManager.getCard(card_name); break;
       case "nachricht" : card = Unidos.CardManager.getCard(card_name); break;
       default : return false;
   }
   card.resetPriorityWhenClickedOn(id);
});

我的 HTML

 <script id="nachricht_card_row_template" type="text/html">
            <div class="normal-box" data-row-id="{{id}}">
                        <div class="img-box">
                            {{#if channel.image}}
                            <img src="{{channel.image}}" vspace="3">
                            {{/if}}
                        </div>
                        <div class="subtitle-box" id="nachrichten-subtitle-box">
                            <span class="options-title" id="title-text">{{channel.name}}</span>
                        </div>
                        <div class="side-text-box">
                            <span class="side-text">{{formatDate datetime}}</span>
                        </div>
                        <div class="small-text">
                            <div class="normal-text"><span class="text-formating">{{text}}</span></div>
                        </div>
            </div>
        </script>

我的 CSS

.normal-box{ /*Container of other tiny boxes*/
    height: 70px;
    border-bottom: 1px solid;
    border-bottom-color: gainsboro;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.5s ease 0.3s;
}
.normal-box.show{
    opacity: 1;
}

如您所见,我想选择 $('.normal-box) ,但我有另一个函数,它添加了一个类,即 .normal-box show...使用上面的代码,我只能使 .normal-box 元素工作,而不是 .normal-box 显示...这就是我对 .normal-box 显示类的意思:enter image description here

我已经试过了:

$('.normal-box, .normal-box show)
$('.normal-box, .show)
$('.normal-box.normal-box show)
$('.normal-box.show)

它们都不起作用。任何帮助将不胜感激

最佳答案

通常,$('.normal-box') 将匹配任何具有类 normal-box 的元素,除非元素是动态添加的,然后您需要使用像这样的事件委托(delegate):

$(document).on('click', '.normal-box', function(){
   //Your code here
});

希望对您有所帮助。

关于javascript - 多个类的选择不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38678542/

相关文章:

javascript - 简单的评级系统

javascript - jQuery 插件中没有冲突是如何工作的

javascript - 从 DOM 中修改/删除后恢复节点/元素

php - 单击刷新 div 中的页面

javascript - 什么可以解释浏览器间歇性地不加载某些 CORS(crossorigin)javascript 文件?

javascript - 变换 rotate() 不适用于 Animate.css

javascript - 如何从 Google map 对象中隐藏公交车?

Javascript - 使用 1 个选择列表填充 2 个文本框

jquery - css 未加载到 jquery 中

html - 如何在 CSS 中设置表格的整个第一行的样式