防止元素失去焦点 [英] Prevent an element from losing focus

查看:112
本文介绍了防止元素失去焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在文档中有很多输入

我们想要打开一个生成文本的对话框并将其置于当前关注的位置输入。

We have a lot of inputs in a document.
We want to open a dialog that generates text and puts that in the currently focused input.

问题在于,当我单击按钮或其他任何内容打开输入失去焦点的对话框时。我无法确定哪个输入必须获取生成的文本。

The problem is that, when I click a button or anything else to open the dialog that input loses focus. I can't determine which input has to get the generated text.

$("#button").click(function(){
    // something should goes here to prevent stealing inputs focus
});

是否有任何解决方案可以防止通过该特殊按钮窃取焦点?

Is there any solution to prevent stealing focus by that special button?

推荐答案

您无法使用表格按钮,只需使用说< span> 让它表现得像一个按钮?

You could not use a form button and just use say a <span> make it behave like a button?

更新:

你可以使用类似

$('span').hover(function(){
    focused_element = $("*:focus").get(0);
});
$('span').click(function(){
    focused_element.focus();
});

查看我的小提琴

这篇关于防止元素失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆