用Javascript往一個p中插入一張圖片
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript"> window.onload = function (){ var bigImg = document.createElement("img"); //創建一個img元素 bigImg.src="http://www.baidu.com/img/baidu_sylogo1.gif"; //給img元素的src屬性賦值 //bigImg.width="320"; //320個像素 不用加px var myp = document.getElementById('myp'); //獲得dom對象 myp.appendChild(bigImg); //為dom添加子元素img }; </script> </head> <body> <p id="myp" style="border:1px solid #eee;width:320px;height:160px;"></p> </body> </html>
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com