动态文本框jquery焦点 [英] dynamic textbox jquery focus

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

问题描述

我正在创建一个输入类型的动态文本框,并帮助跟随
代码
i无法将焦点设置在输入类型上。

i am creating a dynamic text box of input type with the help of following code i am not able to set the focus on the input type.

var elem = document.createElement("input");
elem.type = "text";
elem.id = "txtParent";
elem.setAttribute('onblur', 'SetSpanValueForParent("' + spnText.id + '")');
$(elem).focus();
$(spnText).append(elem);

我也试过这样做
elem.focus();

i have also tried doing this elem.focus();

你可以提供一行声明我怎样才能实现这个

can u provide that one line statement how can i achieve this

推荐答案

你首先需要在设置焦点()之前附加输入。

You first need to append the input, before setting the focus().

元素只有在可见时才能有焦点。

Elements can have focus only if they are visible.

示例:

function fx(spnText)
{
  var elem = document.createElement("input");
  elem.type = "text";
  elem.id = "txtParent";
  elem.setAttribute('onblur', 'SetSpanValueForParent("' + spnText.id + '")');
  $(spnText).append(elem);
  //a little delay before setting the focus
  setTimeout(function(){elem.focus()},50);
}

这篇关于动态文本框jquery焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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