本文介绍了缺少]谷歌地图事件对象的元素列表后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图在onclick事件上调用moreInfo()函数,并为它提供关于click事件的信息。 这里是代码示例: google.maps.event.addListener(SomeArea,'click',showTB); function showTB(event){ // content has the map click event var contentString = event.latLng + '< br> '+'< button onclick =moreInfo('+ event +')>更多< / button>'; infoWindow.setContent(contentString); $ / code> 这里是相关函数moreInfo function moreInfo(e){ var overlayContent = e.latLng document.getElementById(content)。innerHTML = overlayContent; firebug输出: $ b moreInfo([object Object]) 我该如何解决这个问题? 解决方案 c> infoWindow 也可能是 DOMNode 。 创建一个 DOMNode 并将按钮插入此节点,那么您可以将按钮应用于按钮(并传递任何类型的参数): 函数showTB(event){ var contentElement = document.createElement('div'), btn = document。的createElement( '按钮'); contentElement.appendChild(document.createTextNode(event.latLng)); contentElement.appendChild(document.createElement('br')); contentElement.appendChild(btn); btn.appendChild(document.createTextNode('More')); google.maps.event.addDomListener(btn,'click',function(){moreInfo(event);}) infoWindow.setContent(contentElement); 演示: http://jsfiddle.net/doktormolle/N5Etg/ I'm trying to call moreInfo() function on the onclick event and to give it information about the click event.here are code samples:google.maps.event.addListener(SomeArea, 'click', showTB);function showTB(event) { //content has the map click event var contentString = event.latLng + '<br>' + '<button onclick="moreInfo('+event+')">More</button>'; infoWindow.setContent(contentString);}here is relevant function moreInfo function moreInfo(e){ var overlayContent = e.latLng document.getElementById("content").innerHTML = overlayContent;}firebug output: SyntaxError: missing ] after element list moreInfo([object Object])How can I fix this? 解决方案 the content for an infoWindow may also be a DOMNode.Create a DOMNode and insert the button into this node, then you'll be able to apply a click-listener to the button(and pass any type of argument):function showTB(event) { var contentElement = document.createElement('div'), btn = document.createElement('button'); contentElement.appendChild(document.createTextNode(event.latLng)); contentElement.appendChild(document.createElement('br')); contentElement.appendChild(btn); btn.appendChild(document.createTextNode('More')); google.maps.event.addDomListener(btn,'click',function(){ moreInfo(event);}) infoWindow.setContent(contentElement);}Demo: http://jsfiddle.net/doktormolle/N5Etg/ 这篇关于缺少]谷歌地图事件对象的元素列表后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 13:36