不丢失 jquery 上的焦点事件
我有这个 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
,因为我是textarea
的focusedout
代码>
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样防止失去焦点:
代码: http://jsfiddle.net/2qMFX/7/
You can prevent loosing focus like this:
Code: http://jsfiddle.net/2qMFX/7/
我建议您让用户
div
按需关闭。这意味着,在将焦点输入I recommend that you let user close the
div
on-demand. This means that on entering focus to the<textarea>
, you displaydiv
, and ondiv
you have a close button, that use can click and close.