gpt4 book ai didi

javascript - Google map infoWindow 内容中的变量失败

转载 作者:行者123 更新时间:2023-12-02 14:06:28 25 4
gpt4 key购买 nike

我有一个信息窗口,我想从变量中获取数据,但每当我尝试运行它时,这段代码总是失败。

没有变量,这段代码可以正常工作:

content: "<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory

当我将内容分配给变量时:

  var infoWindow = new google.maps.InfoWindow({
var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

content: kontent
});

我得到Unexpected token var kontent = ... 行中出现错误

如何解决我的问题?

最佳答案

infowindows: The InfoWindow constructor takes an InfoWindowOptions object literal, which specifies the initial parameters for displaying the info window.

这意味着,您需要更改此:

 var infoWindow = new google.maps.InfoWindow({
var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='"+mid+"' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

content: kontent
});

致:

var kontent = '"<button onClick="MyObject.joinevent(this.id);" id='
"+mid+"
' class="join btn btn-primary pull-right">Join Event</button><br/><hr/>"+"<b>Event Title</b> "+eventtitle+"<br/>"+"<b>Event Time</b> "+eventtime+"<br/>"+"<b>Event Duration</b> "+eventduration+"<br/>"+"<b>Event Category</b> "+eventcategory';

var infoWindow = new google.maps.InfoWindow({
content: kontent
});

关于javascript - Google map infoWindow 内容中的变量失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40029535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com