jquery判斷div是否顯示或者隱藏 很多時候會要判斷一個div是不是顯示着,沒顯示要怎么處理,顯示的如何處理; 方法很簡單,選擇到你要判斷的div,再用is(':hidden')判斷是否隱藏;或者用is(":visible")判斷是否顯示; 判斷如果顯示或不顯示代碼如: if($('#div').is(':hidden')){ //如果隱藏時。。。 }else{ //如果顯示時。。。 } javarcript 方法: var o =document.getElementById("div1").style.display; if(o=="none") //已經是隱藏狀態 { document.getElementById("div1").innerHTML = ""; //div要顯示的內容 document.getElementById("div1").style.display = ""; //使之可見 } else { document.getElementById("div1").innerHTML = ""; //div要顯示的內容 document.getElementById("div1").style.display = "none"; //使之不可見 }
比較常用的顯示和隱藏:
jQuery("#pay_method p").bind("click", function(){ alert(this.innerHTML); jQuery("#pay_method .icon-select-01").removeClass('icon-select-01').addClass('icon-unselect-01'); jQuery(this).children('i').removeClass('icon-unselect-01').addClass("icon-select-01"); alert(jQuery(this).attr("data-type")); if(atype==0){ $("#boxcoupons").css({ display: "block" }); $("#box-coupons").show(); // var target=document.getElementById("box-coupons"); // alert(target); // target.style.display="block"; // $("#box-coupons").css({ // display:"block", // });
}else{ //$("#box-coupons").hide();
$("#boxcoupons").css({ display: "block" }); } });
