gpt4 book ai didi

javascript - Jquery 焦点显示 div

转载 作者:行者123 更新时间:2023-11-28 19:11:01 25 4
gpt4 key购买 nike

当我单击输入时,它会在两个字段上显示 div。我希望 div 仅出现在选定的输入上。

<强> jsfiddle

$('.example').focus(function() {
$('div.tip').show();
$(document).bind('focusin.tip click.tip',function(e) {
if ($(e.target).closest('.tip, .example').length) return;
$(document).unbind('.tip');
$('div.tip').fadeOut('medium');
});
});
$('div.tip').hide();

最佳答案

我会做类似 this 的事情

正如您所看到的,我已经为您想要显示的每个 div 添加了一个 ID,该 ID 与您单击的输入相关,这样您就可以更灵活地确定元素在 DOM 中的放置位置。

它还隐藏了所有与当前输入无关的 div。

按照评论中的建议,我还将 div 移到了 p 标记之外,以使 HTML 有效。

$('.example').focusin(function() {
$('.tip').hide();
$('#tip-'+$(this).attr('id')).show();
});
$('div.tip').hide();

关于javascript - Jquery 焦点显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30719681/

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