2010-08-24 25 views

Trả lời

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

mà là một phím tắt cho

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

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

+1

Nhưng điều này không chọn các nội dung của lĩnh vực đầu vào, đúng không? – acme

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

jQuerys focus() phương pháp không chọn văn bản trong lĩnh vực đầu vào. Thay vào đó, thêm select():

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

kích hoạt Prototype() chức năng tập trung vào và chọn toàn bộ nội dung của các phần tử của biểu mẫu.

Trong JQuery, hành vi này có thể được nhân rộng với ba chức năng:

// 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(); 
}); 
Các vấn đề liên quan