jQuery 有“存在”函數嗎? - Is there an "exists" function for jQuery?

問題:

How can I check the existence of an element in jQuery?如何檢查jQuery中元素的存在?

The current code that I have is this:我目前的代碼是這樣的:

if ($(selector).length > 0) {
    // Do something
}

Is there a more elegant way to approach this?有沒有更優雅的方法來解決這個問題? Perhaps a plugin or a function?也許是插件或功能?


解決方案:

參考一: https://en.stackoom.com/question/84i參考二: https://stackoom.com/question/84i
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章