【发布时间】:2025-12-29 02:25:12
【问题描述】:
我有一个div 和它的三个span children,当我在click 上div 时使用JQuery 然后使用下面的function 我能够识别出child 是@ 987654332@或clicked
$('.unitContainer').on('click','span',function(){
$('.unitContainer').children('span').each(function () {
$(this).css('color','white');
});
console.log($(this).text()); // "this" is the current element in the loop
$(this).css('color','black'); // This line change attribute of targeted div
});
现在我想要这个事件,如果那个 div 将是 Map 上的自定义控件。
我试过了:
google.maps.event.addDomListener(unitControlDiv, 'click', function() {
$('.unitContainer').children('span').each(function () {
$(this).css('color','white');
});
$(unitControlDiv).css('color','black');
});
还有这个:
google.maps.event.addDomListener(unitControlDiv, 'click', function() {
$('.unitContainer').children('span').each(function () {
$(this).css('color','white');
});
$(this).css('color','black');
});
但两者都不起作用。我现在怎么做才能让它发挥作用?
更新 1
1 : 默认控制 2:我的控件(自定义控件)(具有 3 个跨度的 Div)
更新 2
这个demo 使用JQuery 成为目标span
和
这个demo(地图上的div)没有工作。
【问题讨论】:
-
对不起,'div 将自定义控件'是什么意思?
-
我的意思是我在地图上添加了那个 div。 Google Map 提供的地图上有一些控件,如
ZoomIn btn、ZoomOut Btn'Round Navigator' taht。但是我手动添加了这个 div,所以我认为它是一个自定义控件。 (我想也许是错的) -
@setec 我更新了图片也许现在会更清楚
-
还更新了
JSFiddle两个案例的演示
标签: javascript jquery html google-maps-api-3 addeventlistener