不丢失 jquery 上的焦点事件

发布于 2024-12-16 23:28:06 字数 1005 浏览 3 评论 0原文

我有这个 html:

<div style="display:none" id="myDiv">
 <a href="javascript:adToText('some text 1')">click me</a><br>
 <a href="javascript:adToText('some text 2')">click me</a><br>
 <a href="javascript:adToText('some text 3')">click me</a><br>
</div>

<textarea id="myText">
 hey
</textarea>

javascript:
$("textarea").live("focus",function(){
 $("#myDiv").css("display","block");
});

$("textarea").live("blur",function(){
 $("#myDiv").css("display","none");
});

textarea focus 上,我将 div 样式设置为 display:block 这样我们就可以 单击 JavaScript 链接 该脚本会将文本添加到 textarea

上的 textarea blur 我将 div 样式设置为 display:none

我需要查看 div 链接,以便我可以将它们添加超过 1 次 但发生的情况是,当我点击一个链接时,div设置为display:none,因为我是textareafocusedout代码>

I have this html:

<div style="display:none" id="myDiv">
 <a href="javascript:adToText('some text 1')">click me</a><br>
 <a href="javascript:adToText('some text 2')">click me</a><br>
 <a href="javascript:adToText('some text 3')">click me</a><br>
</div>

<textarea id="myText">
 hey
</textarea>

javascript:
$("textarea").live("focus",function(){
 $("#myDiv").css("display","block");
});

$("textarea").live("blur",function(){
 $("#myDiv").css("display","none");
});

on textarea focus I set the div style to display:block so we can click the javascript link
the script will add text to the textarea

on textarea blur I set the div style to display:none

I need to see the div links so I can add them more then 1 time
but what happens is that when I click a link the div sets to display:none because I am focusedout of the textarea

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧夏天 2024-12-23 23:28:07

您可以像这样防止失去焦点:

$('a').mousedown(function() { return false; })
      .click(function() { alert('works'); });

代码: http://jsfiddle.net/2qMFX/7/

You can prevent loosing focus like this:

$('a').mousedown(function() { return false; })
      .click(function() { alert('works'); });

Code: http://jsfiddle.net/2qMFX/7/

花开浅夏 2024-12-23 23:28:07

我建议您让用户div按需关闭。这意味着,在将焦点输入

I recommend that you let user close the div on-demand. This means that on entering focus to the <textarea>, you display div, and on div you have a close button, that use can click and close.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文