jquery动态添加div
var creatediv = function(){ var parentdiv=$('<div></div>'); //创建一个父div parentdiv.attr('id','parent'); //给父div设置id parentdiv.addClass('parentdiv'); //添加css样式 var childdiv=$('<div></div>'); //创建一个子div childdiv.attr('id','child'); //给子div设置id childdiv.addClass('childdiv'); //添加css样式 childdiv.appendTo(parentdiv); //将子div添加到父div中 parentdiv.appendTo('body'); //将父div添加到body中 };
在div下动态添加img
var bb="http://localhost:8080/VMSInfoDiffusion/"; var server=$("#serverUrl").val();// 访问的地址 var sourcePath=$("#largePath").val(); // 图片的路径a.jsp例如a.jsp,b.jsp,c.jsp var path1="path1";// div的id getImage(sourcePath,path1,server); function getImage(sourcePath1,path2,server){ if(sourcePath1!=null){ var str= new Array(); var str=sourcePath1.split(","); if(str.length>0){//获得div var ul = document.getElementById(path2); for(var i=0;i<str.length;i++){ var li = document.createElement("li"); var img = document.createElement("img"); img.setAttribute("id", "newImg"); img.src = server+"/"+str[i]; li.appendChild(img); ul.appendChild(li); } } } }
相关推荐
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
softwear 2020-08-21
ZGCdemo 2020-08-16
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23
dragonzht 2020-06-17