jquery选择器-getElementById vs jquery

jquery选择器-getElementById vs jquery,jquery,google-maps,jquery-selectors,Jquery,Google Maps,Jquery Selectors,map的这两个定义在功能上是等价的吗 var target = $('#mapcontainer')[0]; console.log(target); // = <div id="mapcontainer" height="311px" width="1708px"> var map = new google.maps.Map(target , options); 及 第二个给了我地图,第一个优雅

map的这两个定义在功能上是等价的吗

    var target = $('#mapcontainer')[0];
    console.log(target);                                // = <div id="mapcontainer" height="311px" width="1708px">
    var map = new google.maps.Map(target , options);

第二个给了我地图,第一个优雅地死去。也许MAPAPI对接收的格式很挑剔


jQuery只是javascript的包装。如果您更关心性能,那么应该使用getElementByID。但是,使用jQuery将提供额外的方法来处理元素。 $document.getElementById'mapcontainer'.jqueryCall; 这将提供jquery方法,同时提高性能。
希望这有帮助!d

它们的相同之处在于返回的结果是相同的。也许map API对接收的格式很挑剔您的两个示例都传递相同的格式。也就是说,它们都传递对DOM元素的引用,假设该元素存在——如果元素不存在,则第一个方法传递未定义的引用,而第二个方法传递null。第一个优雅地死去——这是什么意思?JS控制台中没有错误?与性能无关。只是尝试一些示例来帮助真正理解引擎盖下发生的事情。好的,.jQueryCall是与该元素关联的任何jquery方法。每个人都在使用基本的javascript方法。
    console.log(document.getElementById("mapcontainer"));       // also equals = <div id="mapcontainer" style="height: 311px; width: 1708px;">
    var map = new google.maps.Map(document.getElementById("mapcontainer"), options);