gpt4 book ai didi

javascript - 获取我在 mapbox 中点击的标记的样式

转载 作者:太空宇宙 更新时间:2023-11-04 11:42:21 25 4
gpt4 key购买 nike

我正在尝试获取我单击的图标的样式,以便获取其翻译值。我这样做是因为我想创建一个 div,它在 map 上的位置与点击的图标相同。到目前为止,这是我的网站: http://www.david-halfon.com/radio/index.html

基本上,每当有人按下黄色圆圈时,它周围就会出现一个 div。

这是单击图标时发生的事件的代码:

locale.on('click', function(e) {
$("#music").attr("src", prop.Url);
$(".player").show();
play();
sendWithAjax(prop.Country, prop.City);
$("h1").html(prop.Station);
$("h2").html(prop.Country);
$("h3").html(prop.City);
//console.log($(this).css("transform"));
//console.log($(this).attr("style"));

console.log($(this));

setTimeout(function(){ $("h4").html(globalVar);}, 500);

$(".plusB").show();
$(".shareB").show();

map1.setView(locale.getLatLng(), 4);
playNow = prop.Station;
playNowCountry = prop.Country
playNowCity = prop.City;

});

评论是我到目前为止尝试做的,但它似乎不起作用。

当我尝试 consloe.log(this) 时,我得到“未定义”。

谢谢!!

最佳答案

您没有得到预期的 $(this).css(...) 的原因信息是 this不是常规的 DOM 对象,因为使用 Firebug 可以清楚地显示它:

enter image description here

<img>你想从中获取样式包含在 _icon 中此对象的成员,因此您可以使用例如:

console.log($(this._icon).css('transform'));
console.log($(this._icon).attr('style'));
// and so on

这种方式(在您的网站上使用 Firebug 进行测试)效果很好。

顺便说一句,我不明白为什么点击事件的目标是这个对象而不是 <img> ...

顺便说一句,这个网站是个好主意:太棒了!

关于javascript - 获取我在 mapbox 中点击的标记的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31231322/

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