6

原型的激活函数

如果是文本输入,则将焦点放在表单控件上并选择其内容

根据原型网站。IE

$('my_element_id').activate();

jQuery中的等效函数是什么?

4

4 回答 4

5
$('#my_element_id').focus();

这是一个快捷方式

$('#my_element_id').trigger('focus');

http://api.jquery.com/focus/

于 2010-08-24T18:51:59.680 回答
4

Prototype 的 activate() 函数关注并选择表单元素的全部内容。

在 JQuery 中,可以使用三个函数复制此行为:

// Focus
$('my_element_id').focus();

// Focus and select the content.
$('my_element_id').focus().select();

// Focus and select the content without problems in Google chrome
$('my_element_id').focus().select().mouseup(function(event){
  event.preventDefault();
});
于 2011-11-21T17:06:14.657 回答
2
$('my_element_id').focus();
于 2010-08-24T18:52:46.280 回答
1

jQuerysfocus()方法不会选择输入字段中的文本。相反,添加select()

$('my_element_id').focus().select();
于 2011-10-20T13:32:23.893 回答