簡體   English   中英

使用JavaScript檢查是否不顯示

[英]Check if display is none using Javascript

我正在使用javascript並想按一個按鈕,但是如果按鈕為“ display:none”,那么我想跳過它。

所以目前我有這段代碼:

var sf = document.querySelectorAll(input.button")[0];

現在以一個示例為例,頁面上可能還有其他“ input.buttons”被設置為“ display:none”,我想跳過這些,只單擊可見的按鈕。

我感謝任何建議。

var sf = document.querySelectorAll(input.button")[0];

以上陳述有問題。 如果要選擇按鈕類型的輸入, document.querySelectorAll(input.button")[0]將返回一個空數組,請使用以下命令

var sf = document.querySelectorAll("input[type='button']");        // array of button
var sf = document.querySelectorAll("input[type='button']").[0];    // first index element  

假設你sf is an array

for (var i = 0; i < sf.length; i++) {
    if (sf[i].style.display != "none") {
        console.log(elem[i])
    }
}

要檢查display: none jquery中display: none使用子選擇器(通常稱為) :visible

if(document.getElementById("id").is(':visible')){
 // YES, ITS WORKING..!
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM