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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章