getElementById
是單數,不是複數。你也不需要.length
,因爲它意味着不同的節點。
if(document.getElementById('profile-advanced-details')) {
document.getElementById('page-body').style.height = "1500px";
}
您可能還可以使用CSS,但前提是參考要素(「型材先進範圍」)爲目標之前(「頁體」)。這可能不是這裏的情況,但它是一個很好的把戲知道:
#profile-advanced-details + #page-body,
#profile-advanced-details + * page-body {height:1500px}
/* the following may work in CSS4: */
!#page-body #profile-advanced-details,
!#page_body + #profile-advanced-details,
!#page_body + * #profile-advanced-details {height:1500px}
$#page-body #profile-advanced-details,
$#page_body + #profile-advanced-details,
$#page_body + * #profile-advanced-details {height:1500px}
#page-body! #profile-advanced-details,
#page_body! + #profile-advanced-details,
#page_body! + * #profile-advanced-details {height:1500px}
#page-body$ #profile-advanced-details,
#page_body$ + #profile-advanced-details,
#page_body$ + * #profile-advanced-details {height:1500px}
/* The different ones are partially because I don't remember the spec,
but mostly because it's changing */
如果(的document.getElementById( '輪廓先進-細節')。長度<= 0){} – algorhythm