将字符串传递到对象javascript中
我获取将字符串传递到对象javascript中,javascript,Javascript,我获取li元素的id,并希望使用该名称访问对象的该部分。我试图添加var selectionId,其中包含我想要的节的名称,例如cars,但我得到了一个错误。有办法吗 谢谢 $(document).ready(function() { $(".markerSelection").click(function() { var selectionId = $(this).attr("id"); drop(selectionId); }); }); va
li
元素的id
,并希望使用该名称访问对象的该部分。我试图添加var selectionId
,其中包含我想要的节的名称,例如cars
,但我得到了一个错误。有办法吗
谢谢
$(document).ready(function() {
$(".markerSelection").click(function() {
var selectionId = $(this).attr("id");
drop(selectionId);
});
});
var markers = {
shopping : [
new google.maps.LatLng(52.26183, -7.11339),
new google.maps.LatLng(52.26134, -7.11226),
new google.maps.LatLng(52.26067, -7.11181),
new google.maps.LatLng(52.26003, -7.11033)],
cars : [
new google.maps.LatLng(52.26183, -7.11339),
new google.maps.LatLng(52.26134, -7.11226),
new google.maps.LatLng(52.26067, -7.11181),
new google.maps.LatLng(52.26003, -7.11033)]
};
var iterator = 0;
function drop(selectionId) {
clearOverlays();
for (var i = 0; i < markers.selectionId.length; i++) {
setTimeout(function() {
addMarker();
}, i * 200);
}
}
$(文档).ready(函数(){
$(“.markerSelection”)。单击(函数(){
var selectionId=$(this.attr(“id”);
drop(selectionId);
});
});
变量标记={
购物:[
新google.maps.LatLng(52.26183,-7.11339),
新google.maps.LatLng(52.26134,-7.11226),
新的google.maps.LatLng(52.26067,-7.11181),
新google.maps.LatLng(52.26003,-7.11033)],
汽车:[
新google.maps.LatLng(52.26183,-7.11339),
新google.maps.LatLng(52.26134,-7.11226),
新的google.maps.LatLng(52.26067,-7.11181),
新google.maps.LatLng(52.26003,-7.11033)]
};
var迭代器=0;
函数下拉列表(selectionId){
clearOverlays();
对于(变量i=0;i
如果试图通过变量键访问对象属性,则需要使用数组表示法:
... markers[selectionId].length ...
标记。selectionId
失败,因为它相当于标记[“selectionId”]
如果您试图通过变量键访问对象属性,则需要使用数组表示法:
... markers[selectionId].length ...
markers.selectionId
失败,因为它相当于markers[“selectionId”]
什么下一票-无辜光环-[可能因为误解答案而删除了否决票]什么否决票-无辜光环-[可能因为误解答案而删除了否决票,也可能没有]