Not exactly!!(不完全是!!)
document.getElementById('contents'); //returns a HTML DOM Object
var contents = $('#contents'); //returns a jQuery Object
In jQuery, to get the same result as document.getElementById
, you can access the jQuery Object and get the first element in the object (Remember JavaScript objects act similar to associative arrays).(在jQuery中,要获得与document.getElementById
相同的结果,您可以访问jQuery Object并获取对象中的第一个元素(记住JavaScript对象的行为类似于关联数组)。)
var contents = $('#contents')[0]; //returns a HTML DOM Object
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…