簡體   English   中英

jQuery - 檢查輸入是否不是選擇字段

[英]jQuery - check if an input is not a select field

如何確定輸入字段是否不是select

我嘗試了if($(el).not("select")) ,我也得到了選擇......

if(!$(el).is("select")) {
    // the input field is not a select
}

$(el).not("select")為您提供數組。 在布爾表達式中,Array始終為true 但是在你不應用之后,這個元素數組將不包含選擇。 見工作示例

.not()方法返回一個新的jQuery對象,其中包含原始對象中與選擇器不匹配的所有內容。
你不能在if語句中使用它。

相反,您使用.is方法,該方法檢查元素是否與選擇器匹配並返回布爾值。

if (!$(el).is('select'))

<select>標簽一個類怎么樣:

$(el + ":not('.select')")
if ($(el)[0].nodeName != 'select')
if($(el).selectedIndex)

如果它具有SelectedIndex屬性,則它是<SELECT>

暫無
暫無

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

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