轉自:http://www.jb51.net/article/65153.htm
關於jQuery()方法的第二個參數,有下面這幾種用法:
1.jQuery(selector, [context])
這種用法,相當於 $(context).find(selector) 或者 context.find(selector)
2.jQuery(html, [ownerDocument])
文檔對ownerDocument的解釋是:“創建DOM元素所在的文檔”
也就是說,如果你要編寫挎document的腳本,比如iframe或者用window.open開一個新窗口,可能會用得着它
3.jQuery(html, props)
這個應該比較常用了,直接貼代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
$( "<input>" , { type:
"text" , val:
"Test" , focusin:
function () { $( this ).addClass( "active" ); }, focusout:
function () { $( this ).removeClass( "active" ); } }).appendTo( "form" ) |
也就是說,props內的屬性會像.attr()方法一樣,被設置到新創建的標籤內