0

我想将变量中的坐标值存储为数组

var initial_location = new Array ();
initial_location = $('ol.locations_list li a:first').?????;

--------HTML ------------

<ol class="locations_list">
<li class="active_location"><a cityid="0" type="street_address" radius="81.00" coords="['43.2342080','-77.0683780']"><span class="location_title"> common 81.00 km of</span>
21 Carlton Street, Sodus, NY 14551, USA</a>

<a class="remove_location" style="float:right;" data-nid="106" title="Remove this location">
      x
    </a></li><li><span class="location_title">
      Home 
    </span>
       New York, NY, USA
    <a class="remove_location" style="float:right;" data-nid="109" title="Remove this location">
      x
    </a></li></ol>

你可以看到 coords="['43.2342080','77.0683780']" 是一个数组..我也可以用不同的方式渲染,比如大括号。

4

1 回答 1

1

尝试这个:

var initial_location = eval('(' + $('ol.locations_list li:first a:first').attr('coords') + ')');
于 2013-01-26T22:20:45.263 回答