有什么区别吗?
$(this).parent().children(".name") 和
$(this).parent().find(".name")?这两个函数都返回相同的对象。当我这么做
console.log($(this).parent().children(".name"));和
console.log($(this).parent().children(".name"));这两个函数都在控制台上打印div名称的对象。
发布于 2014-07-18 07:27:03
基本上,.children()在查找子元素的第一级时,.find()将查找后代元素。这是两者之间的基本区别。
例如,如果您在嵌套级别上有.name,那么.children()不会在.find()返回它的同时返回它。
要了解更多信息,只需阅读.children()和.find().
发布于 2014-07-18 07:32:37
这将返回所有具有类名的子级。
console.log($(this).parent().children(".name"));这将返回满足该类的第一个对象。
$(this).parent().find(".name")https://stackoverflow.com/questions/24819426
复制相似问题