javascript - jquery添加为什么没办法添加封闭标签
怪我咯
怪我咯 2017-04-11 12:34:29
[JavaScript讨论组]

$("#id").append('');

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

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
怪我咯

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号