2010-08-24 7 views

Antwort

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

, die eine Abkürzung für

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

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

+1

Aber dies den Inhalt des Eingabefeldes nicht wählen, nicht wahr? – acme

2
$('my_element_id').focus(); 
1

jQuerys focus() Methode nicht den Text in das Eingabefeld auszuwählen. Stattdessen fügen select():

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

Prototype activate() Funktion konzentriert sich auf und wählt den gesamten Inhalt der Elemente des Formulars.

In JQuery, kann dieses Verhalten mit drei Funktionen repliziert werden:

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