我需要帮助才能使onclick功能在我的InfoWindow
内容中运行。
以下是我的代码的一部分:
for (i = 0; i < markers.length; i++) {
var position = new google.maps.LatLng(markers[i][0], markers[i][1]);
var icon = {
url:"http:///".concat(markers[i][3]),
scaledSize: new google.maps.Size(20, 20), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(0, 0)
};
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][4].toString().concat(' ').concat(markers[i][5].toString()),
icon: icon,
url:'im:<sip:'+markers[i][6]+'>'
});
var infowindow = new google.maps.InfoWindow({
content: ''
});
marker.addListener('mouseover', function() {
infowindow.setContent('<p><label>Name:</label> '+this.title+'</p>' +
'<center><button class="btn btn-primary" \n\
onclick="myFunction(){ window.location.assign(this.url);}">Call</button></center>');
infowindow.open(map, this);
});
}
&#13;
答案 0 :(得分:0)
INSERT INTO contact(sender_id, receive_id, message, date_time )
SELECT ?, ?, ?, unix_timestamp()
FROM dual
WHERE NOT EXISTS(
SELECT count(*) AS num_day,
FROM contact
WHERE user_id = ?
AND date_time > unix_timestamp(DATE_SUB(now(), INTERVAL 1 day))
HAVING num_day > 4
)
处理程序实际上并不执行任何操作。你只需在其中定义一个函数。试试这个:
onclick
答案 1 :(得分:0)
在你的onclick处理函数这个将引用按钮元素而不是标记对象,这就是为什么它不起作用,因为按钮不是任何属性,如url。
您可以使用带有href的标记重定向到您想要的位置
试试这个:
for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][0], markers[i][1]);
var icon = {url:"http:///".concat(markers[i][3]),
scaledSize: new google.maps.Size(20, 20), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(0, 0) };
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][4].toString().concat(' ').concat(markers[i][5].toString()),
icon: icon,
url:'im:<sip:'+markers[i][6]+'>'
});
var infowindow = new google.maps.InfoWindow({
content: ''
});
marker.addListener('mouseover', function() {
infowindow.setContent('<p><label>Name:</label> '+this.title+'</p>' +
'<center><a class="btn btn-primary" href="'+this.url+'">Call</a></center>');
infowindow.open(map, this);
});