gpt4 book ai didi

javascript - 单击事件时提醒元素属性

转载 作者:行者123 更新时间:2023-12-03 07:37:35 24 4
gpt4 key购买 nike

我试图在单击全键时提醒 data-keyid。

$(function() {
$('.fullkey').click( function (){
var keyId = $(this).attr('data-keyid');
alert(keyId);
});

});

<div class="fullkey">
<div data-keyid="c-key"></div>
</div>

最佳答案

Use .find to get the child nodes of the parent element. You can filter the set of returned elements using specific selector. $(this) is parent selector in this example.

[data-keyid] 选择器可用于查找属性为 data-keyid

的子节点

试试这个:

$(function() {
$('.fullkey').click(function() {
var keyId = $(this).find('[data-keyid]').attr('data-keyid');
alert(keyId);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="fullkey">
<div data-keyid="c-key">Click Here</div>
</div>

<div class="fullkey">
<div data-keyid="d-key">Click Here</div>
</div>

<div class="fullkey">
<div data-keyid="e-key">Click Here</div>
</div>

关于javascript - 单击事件时提醒元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35545919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com