【发布时间】:2020-08-12 15:07:14
【问题描述】:
<script>
function showRank(){
// I don't know what to do now
}
<script>
<section>
<div data-index='1'>
<p>First</p>
<button onclick='showRank()'>First</button>
</div>
<div data-index="2">
<p>Second</p>
<button onclick='showRank()'>Second</button>
</div>
<div data-index="3">
<p>Third</p>
<button onclick='showRank()'>Third</button>
</div>
</section>
当我单击任何一个按钮时,我想要 console.log() 按钮所在的 div。 例如:
输入-:Clicked the button 'First'
输出-:
<div data-index='1'>
<p>First</p>
<button onclick='showRank()'>First</button>
</div>
【问题讨论】:
标签: javascript custom-data-attribute