转自: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()方法一样,被设置到新创建的标签内