开发者

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

开发者 https://www.devze.com 2023-01-13 11:04 出处:网络
Prototype\'s activate function Gives focus to a form control and selects its contents if it is a text input

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

精彩评论

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