这里是否存在OpenLayers/jQuery冲突?
这是我在controller js.coffee文件中的咖啡脚本代码。我只是试图打开一个以特定位置为中心的简单地图。我的地图可以工作,并且会触发这里是否存在OpenLayers/jQuery冲突?,jquery,ruby-on-rails,coffeescript,openlayers,Jquery,Ruby On Rails,Coffeescript,Openlayers,这是我在controller js.coffee文件中的咖啡脚本代码。我只是试图打开一个以特定位置为中心的简单地图。我的地图可以工作,并且会触发moveend\u事件回调,因为如果我取消注释警报(“hello”)调用,它可以正常工作 $(document).ready -> map = undefined options = projection: new OpenLayers.Projection('EPSG:900913') displayProjection
moveend\u事件
回调,因为如果我取消注释警报(“hello”)
调用,它可以正常工作
$(document).ready ->
map = undefined
options =
projection: new OpenLayers.Projection('EPSG:900913')
displayProjection: new OpenLayers.Projection("EPSG:4326")
center: new OpenLayers.LonLat(-115.540123, 54.073189)
controls: [new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher()]
eventListeners:
'moveend': moveend_event
map = new OpenLayers.Map("map_element", options)
osm = new OpenLayers.Layer.OSM('OpenStreetMap Layer')
map.addLayer osm
map_center = new OpenLayers.LonLat(-115.540123, 54.073189).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject())
map.setCenter(map_center, 11)
moveend_event = ->
#alert "Hello!"
#$(".map_location").innerHTML "Hello!"
我很接近,但不能。我想我可能有Openlayers/jQuery冲突。如果我尝试使用$(“.map\u location”).innerHTML“Hello!”
设置我的map\u location div,页面创建者和错误控制台将显示:
TypeError:“未定义”不是函数(正在计算
“$”(“.map_location”).innerHTML(“你好!”)
如果有帮助的话,我会在打开层之前加载jquery。我在谷歌上搜索了一下,可能是jQuery的noConflict模式(http://api.jquery.com/jQuery.noConflict/)但是我是一个javascript新手,我不知道如何解决这个问题。我确信这是一个简单的修复方法,但我目前还没有任何线索。
innerHtml
不是jQuery函数,请使用$('selector').html(此处为新html)
;相反
html
是jQuery与javascript的innerHtml
相对应的版本,我是一个正式的呆子——这就解决了它。