我如何创建这个条件分支。如果带有 ID 产品的 HTML 代码中?如果 #products 确实存在于实际文档中?
感谢您的回复!
伪 Javascript (JQuery)
If ( $('#products').existOn.(document) ) == true {
//do this
}
最佳答案
使用length
:
if ( $('#products').length > 0){
// element is present
}
关于javascript - JQuery - If ( $ ('#products' ).existOn.(document) ) == true {//这样做},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4655743/