原始DOM元素与jQuery对象 [英] Raw DOM element vs. jQuery object

查看:60
本文介绍了原始DOM元素与jQuery对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看以下来自 http://jqfundamentals.com/chapter/的显式迭代示例jquery-basics

$( 'li' ).each(function( index, elem ) {
  // this: the current, raw DOM element
  // index: the current element's index in the selection
  // elem: the current, raw DOM element (same as this)
  $( elem ).prepend( '<b>' + index + ': </b>' );
});

评论引用 elem 作为原始DOM元素,但代码在 elem 上调用 .prepend()

The comments refer to elem as a raw DOM element, but then the code calls .prepend() on elem.

我刚刚开始使用jQuery,但我的理解是你只能在jQuery对象上调用jQuery方法 - 而不是原始DOM元素。我误解了吗?

I'm just getting started with jQuery, but it's my understanding you can only call a jQuery method on a jQuery object - not on a raw DOM element. Am I misunderstanding?

推荐答案

代码不会调用 prepend on elem ,它在 $(elem)上调用它,使其成为一个jquery对象。

The code does not call prepend on elem, it calls it on $(elem) making it a jquery object.

这篇关于原始DOM元素与jQuery对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆