我有两个独立的元素和按钮来控制同样的事情。
我已经设置了一个data-attr
so _2元素(做同样的事情)具有相同的data-attr
值--例如,左上角的dosomething
具有相同的数据--attr值与左下角的domething2
相同。
现在,当单击左上角的dosomething2
时,我想隐藏左下角的dosomething
,而单击左上角的dosomething
时,应该隐藏自己。
所以“当点击左上角的dosomething
时,它应该隐藏自己。”我做了这个:
$('.dosomething').click(function (evt) {
$('.dosomething').fadeIn()
$(this).fadeOut()
})
我想不出怎么做我的:
$('.dosomething2').click(function (evt) {
使用相同的dosomething
值获取顶部的data-attr
发布于 2022-08-30 13:58:24
我不确定这能帮到你。但是你可以像下面这样使用数据。
jQuery
$('a[data-dosomething="true"]').click(function(event) {
$(this).fadeOut()
});
HTML
<a data-dosomething="true" href="#"> dosomething</a>
<a data-dosomething="true" href="#"> dosomething 2</a>
https://stackoverflow.com/questions/73543539
复制相似问题