【发布时间】:2016-07-31 03:58:27
【问题描述】:
我正在尝试获取 <g> 标签内的属性
这里是gtag的属性:
我要抢物业:病房
所有 g 标签都有点击事件,但我无法获取 ajax 请求所需的 ward 值,这里是 js:
$(".map-wrapper").on("click", "g", function(event) {
event.preventDefault();
console.log("I want this to be the value of the ward property");
});
嵌套查询类似于 ["data"]["properties"]["ward"]
【问题讨论】:
-
为什么不直接使用d3获取数据呢?类似
allgs.forEach(function(g) {console.log(d3.select(g).data())}) -
你可以使用jquery的.prop()来获取它吗? api.jquery.com/prop
-
这就是我为获得所需价值所做的工作
$(".map-wrapper").on("click", "g", function(event) { event.preventDefault(); $ward = $(this); console.log($ward[0].__data__.properties.ward); })'code -
@Cyril 和 JordanHendrix,感谢您的建议,我尝试了他们两个但无法让他们工作...
标签: jquery html d3.js svg geojson