<div style="display:block;"> <input/> </div> <div style="display:none;"> <input/> </div>
如上的兩個input元素,獲取兩個input元素,常規的按index、id或判斷等形式也能實現,可是很麻煩,能夠用如下辦法css
$(".div[style='display:block;'] input")
注意「;」分號不能省略.html
這裏的style是指元素的style屬性,並不是css屬性,不然以下改變以後一樣的方法獲取元素會失效this
if($(this).css("display")=='none'){ $(this).attr('display','block'); }else{ $(this).css('display','none'); }
如要操做css屬性,可選用attr方法,如spa
if($(this).css("display")=='none'){ $(this).attr('style','display:block;'); }else{ $(this).attr('style','display:none;'); }
如欲詳細瞭解css屬性與元素屬性,請移步@參考文章code