jquery append方法无法加入img标签

yiyefangzhou24 2016-11-23 10:28:34
	var tipe ="<div style=\"height: auto; margin-top: 15px; padding-top: 65px; padding-bottom: 80px;\">"
+"<img src=\"./images/loading.gif\">"
+"<a href=\"http://test.com/feedback.html\"><button class=\"pull-left btn-success btn subbtn\" style=\"font-size: 16px;\">"
+"test1</button></a>"
+"<a href=\"http://test.com/feedback.html\"><button class=\"pull-left btn-warning btn subbtn\" id=\"shile\" style=\"font-size: 16px;\">"
+"test2</button></a></div><br><br><br>";
$("#textcontent").append(tipe);

这个div添加成功了,但是查询添加后的源码,发现只有两个button,<img src=\"./images/loading.gif\">这句凭空消失了。
...全文
725 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yiyefangzhou24 2016-11-24
  • 打赏
  • 举报
回复
非常感谢各位,我查到原因了,因为浏览器缓存问题,我改了源码结果因为缓存没有清空在访问,就没有显示改过的东西
  • 打赏
  • 举报
回复
引用 楼主 yiyefangzhou24 的回复:
	var tipe ="<div style=\"height: auto; margin-top: 15px; padding-top: 65px; padding-bottom: 80px;\">"
					+"<img src=\"./images/loading.gif\">"
					+"<a href=\"http://test.com/feedback.html\"><button class=\"pull-left btn-success btn subbtn\" style=\"font-size: 16px;\">"
					+"test1</button></a>"
					+"<a href=\"http://test.com/feedback.html\"><button class=\"pull-left btn-warning btn subbtn\" id=\"shile\" style=\"font-size: 16px;\">"
					+"test2</button></a></div><br><br><br>";
					$("#textcontent").append(tipe);
这个div添加成功了,但是查询添加后的源码,发现只有两个button,<img src=\"./images/loading.gif\">这句凭空消失了。
这段代码没问题啊,你具体说说使用情况,还有具体出现的问题
lzh_me 2016-11-23
  • 打赏
  • 举报
回复
首先你是怎么执行的你这段代码?怎么查询的源码? 放在$(function(){});中或者通过主动事件,因为是动态添加的数据,查看源码是看不到的。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Insert title here</title>
        <script type="text/javascript" src="../js/jquery-3.1.1.min.js"></script>
    </head>
    <body>
        <input type="button" name=""button id="button_" value="click"/>
        <div id="text_content">

        </div>
        <script type="text/javascript">
            $(function() {
                $('#button_').on('click', function() {
                    var tipe = "<div style=\"height: auto; margin-top: 15px; padding-top: 65px; padding-bottom: 80px;\">" 
                    + "<img src=\"../images/1.jpg\">" 
                    + "<a href=\"http://test.com/feedback.html\"><button class=\"pull-left btn-success btn subbtn\" style=\"font-size: 16px;\">" 
                    + "test1</button></a>" 
                    + "<a href=\"http://test.com/feedback.html\"><button class=\"pull-left btn-warning btn subbtn\" id=\"shile\" style=\"font-size: 16px;\">" 
                    + "test2</button></a></div><br><br><br>";
                    
                    $("#text_content").append(tipe);
                });
            });

        </script>
    </body>
</html>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧