jquery 用 find查找一个元素的时候,怎样才能知道找到还是没找到?
- 作者: 简单3355155
- 来源: 51数据库
- 2021-07-08
jquery 用 find查找一个元素的时候,怎样才能知道找到还是没找到?
find() 方法获得当前元素集合中每个元素的后代
可以判断是否为undefined
$(".comment_list").find(".comment")[0] == undefined
也可以用size()判断有多少个
$(this).closest('.comment').find(".show_remain_reply").size()
也可以用length判断有多少个
$(this).closest('.comment').find(".show_remain_reply").length
推荐阅读
