开发者

What is the jQuery equivalent of the Prototype function .activate()

Prototype's activate function

Gives focus to a form control and selects its contents if it is a text input

according to the Prototype w开发者_JAVA技巧ebsite. i.e.

$('my_element_id').activate();

What is the equivalent function in jQuery?


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

which is a shortcut for

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

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


Prototype's activate() function focuses on and selects the entire contents of the elements of the form.

In JQuery, this behavior can be replicated with three functions:

// 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();
});


$('my_element_id').focus();


jQuerys focus() method does not select the text in the input field. Instead, add select():

$('my_element_id').focus().select();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜