随机添加数据
function addTest() {
var str=""; var temp='<div class="massage-list">' +'<span>日程</span>' +'<span>党支部会议</span>' +'<span>01月11日15时30分</span></div>' +'<div class="massage-list">' +'<span>日程</span>' +'<span>联盟篮球赛</span>' +'<span>01月13日13时30分</span></div>';var num=Math.floor(Math.random()*3); for(var i = 0;i<= num; i++){ str += temp; } $("#List").append($(str));}
显示隐藏div$(function(){ $('#List').empty(); addTest() });function display(figure){ var traget=document.getElementById(figure); if(traget.style.display=="none"){ traget.style.display="block"; }else{ traget.style.display="none"; } }切换div<span id="hehed">红的</span> <span id="heihei">黄的</span> <!--<span class="hehe">黄的</span><br/>--> <div style ="width:100px; height:100px; background:red; display:block; " id ="div1"> This is a test ! </div> <div style ="width:100px; height:100px; background:yellow; display:none;" id ="div2"> This is a test !</div> <script src="assets/global/plugins/jquery.min.js" ></script> <script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" ></script> <script> var oBtn = document.getElementById('hehed'); var oBtn1 = document.getElementById('heihei'); var oDiv1 = document.getElementById('div1'); var oDiv2 = document.getElementById('div2'); oBtn.onclick = function(){ if(oDiv1.style.display == 'block'){ oDiv2.style.display = 'none'; }else{ oDiv2.style.display = 'none'; oDiv1.style.display = 'block'; } }; oBtn1.onclick = function(){ if(oDiv1.style.display == 'block'){ oDiv1.style.display = 'none'; oDiv2.style.display = 'block'; }else{ oDiv2.style.display = 'none'; oDiv1.style.display = 'block'; } }; </script>