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();
精彩评论