【发布时间】:2019-01-03 05:55:43
【问题描述】:
如何仅在我单击的元素的子元素(由其类标识)上激活单击事件?
我尝试了这个,但似乎激活了页面上 .a-collaps-button 的所有 onclick 事件(我有多个 .collaps-button 和多个 .a-collaps-button)
<button class="collaps-button">
<a href="#adminModal" class="a-collaps-button" data-toggle="modal" onclick="showModalContentjs('modificy')">Modificy</a>
</button>
$('.collaps-button').click(function () {
$(this).children('.a-collaps-button').click();
});
对于 CSS,我这样做并且它有效
$(function () {
$('.collaps-button').hover(function () {
$(this).children('.a-collaps-button').css('color', '#f44242');
$(this).children('.a-collaps-button').css('text-decoration', 'none');
}, function () {
$(this).children('.a-collaps-button').css('color', 'white');
$(this).children('.a-collaps-button').css('text-decoration', 'none');
});
});
【问题讨论】:
-
为什么要使用 js 来设置悬停 css 样式?另外我不认为按钮内的锚是有效的
-
@Pete 我将重新打开它,因为虽然该副本与 OPs 问题相匹配,但其 HTML 中存在巨大缺陷,这使得问题的意义没有实际意义。
标签: javascript jquery html css