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

标签 javascript jquery css google-maps mapbox

我正在尝试获取我单击的图标的样式,以便获取其翻译值。 我这样做是因为我想创建一个 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/

相关文章:

html - 仅将 colgroup 类应用于某些行

javascript - 如何编辑 jquery slider

javascript - jQuery .val() 程序

javascript - 我如何让 JQuery 语句等到它完成后再继续?>

javascript - Highcharts - 导出到 base64

javascript - 如何使用javascript填充html表格而不使用div?

javascript - 如何使我的网站在移动设备上的 View 尺寸更小以适合移动设备屏幕

android - phonegap android ajax over ssl 失败

javascript - 更改后重新加载 DOM

php - 表单元素不可点击html css