首页 > jquery添加为什么没办法添加封闭标签

jquery添加为什么没办法添加封闭标签

$("#id").append('<img src="src" />');

就像这样添加一个img标签,但是为什么添加进去是没有封闭的呢?
在HTML里是这样的<img src="src">


img属于自动封闭标签

另外你那个js代码可以正常运行? 不应该是

$("#id").append("<img src='src'>");

http://api.jquery.com/jQuery/...

When the parameter has a single tag (with optional closing tag or quick-closing) — $( "<img />" ) or $( "<img>" ), $( "<a></a>" ) or $( "<a>" ) — jQuery creates the element using the native JavaScript .createElement() function.

也就是说不是直接插入的

是先解析html->得出是单个的img->使用createElement

【热门文章】
【热门文章】