我有一些相同的按钮和容器;
类似于:
<div>
<button class="myCoolButton">
btn1
</button>
</div>
<div class="myCoolContainer">
container
</div>
<div>
<button class="myCoolButton">
btn1
</button>
</div>
<div class="myCoolContainer">
container
</div>
<div>
<button class="myCoolButton">
btn1
</button>
</div>
<div class="myCoolContainer">
container
</div>
因此,当用户单击按钮时,我需要在下面的容器中显示一些信息。但我如何才能了解我需要使用什么容器?将带有bindend容器的属性放置到按钮上好吗?什么是最佳实践?
注意:日历必须显示在黄色矩形中
最佳答案
$('buttonselector').click(function(){
$(this) // get clicked button
.parent() // parent of clicked buton, i.e div at odd place
.next() // next div to parent div of clicked button, i.e, div at even place
.html('set some value') // set value to adjacent div
})
编辑
<div>
<button id="btn1">
btn1
</button>
</div>
<div id="Container_btn1">
container
</div>
$('#btn1').click(function(){
var name= $(this).attr('id');
$("#container_"+ name).html('set some value')
});
关于javascript - 许多按钮->容器元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7158316/