怎样用javascript在html中插入一段代码

来源:互联网 发布:路由器主人网络是什么 编辑:程序博客网 时间:2024/05/12 03:01

<div style="position:relative;">

<divid="container1997"></div>

<imgsrc="img/2.png" onclick="showEarth(1997)"style="width:50px;height:10px;">

</div>

<div id="container1997"></div>中插入一段代码<img src="img/site.png" style="z-index: 1100; width:10px;position:absolute; bottom: -5px;left:40%;" >

代码如下:

html1= ‘<img src="img/site.png" style="z-index: 1100; width:10px;position:absolute; bottom: -5px;left:40%;" >’;

id=“#container1997”;

$(id).html(html1);

注:html是完全替换,用$(id).html(html1);将替换掉<div id="container1997"></div>中的全部内容,若用append则是加一段内容。



0 0
原创粉丝点击