JQuery每日函数:核心jQuery(html)
jQuery(html)
You can pass in plain HTML Strings written by hand, create them using some template engine or plugin, or load them via AJAX. There are limitations when creating input elements, see the second example. Also when passing strings that may include slashes (such as an image path), escape the slashes. When creating single elements use the closing tag or XHTML format. For example, to create a span use $("<span/>") or $("<span></span>") instead of without the closing slash/tag. 返回值jQuery
参数html (String) : 用于动态创—OM元素的HTML标记字符串
示例动态创建一个 div 元素(以及其中的所有内容),并将它追加到 body 元素中。在这个函数的内部,是通过临时创建一个元素,并将这个元素的 innerHTML 属性设置为给定的标记字符串,来实现标记到 DOM 元素转换的。所以,这个函数既有灵活性,也有局限性。
jQuery 代码:
$("<div><p>Hello</p></div>").appendTo("body");创建一个 <input> 元素必须同时设定 type 属性。因为微软规定 <input> 元素的 type 只能写一次。
jQuery 代码:
// 在 IE 中无效:$("<input>").attr("type", "checkbox");
// 在 IE 中有效:
$("<input type='checkbox'>");