jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
$(html)
$(html)

根据提供的原始HTML标记字符串,动态创建由jQuery对象包装的DOM元素。

返回值:jQuery

参数:

  • html (String): 用于动态创建DOM元素的HTML标记字符串
 
示例1:

动态创建一个div元素(以及其中的所有内容),并将它追加到ID值为body的元素中。在这个函数的内部,是通过临时创建一个元素,并将这个元素的innerHTML属性设置为给定的标记字符串,来实现标记到DOM元素转换的。所以,这个函数既有灵活性,也有局限性。

jQuery 代码:

$("<div><p>Hello</p></div>").appendTo("#body")

 
$( html )

Create DOM elements on-the-fly from the provided String of raw HTML.

Return value: jQuery
Parameters:

  • html (String): A string of HTML to create on the fly.

Example:

Creates a div element (and all of its contents) dynamically, and appends it to the body element. Internally, an element is created and its innerHTML property set to the given markup. It is therefore both quite flexible and limited.

 $("<div><p>Hello</p></div>").appendTo("body")