0

我正在使用类“gmapItems”动态创建元素。我需要为每个元素导出一个数组。

有任何想法吗?

HTML:

<div class="gmapItems">
<input type="text" class="input-medium googleMapCity" value='1'>
<input type="text" class="input-medium googleMapAddress" value='1'>
<textarea class="input-medium googleMapInformation" value='1'></textarea>
</div>

<div class="gmapItems">
<input type="text" class="input-medium googleMapCity" value='2'>
<input type="text" class="input-medium googleMapAddress" value='2'>
<textarea class="input-medium googleMapInformation" value='2'></textarea>
</div>

查询:

    $("#AddGoogleMap").on('click', function () {            
    mapMarkers = new Array();
    $('.gmapItems').each(function(){
    gmapCity = $('.googleMapCity').val();
    gmapAddress = $('.googleMapAddress').val();
    gmapInfo = $('.googleMapInformation').val();  
    mapMarkers.push(gmapCity, gmapAddress, gmapInfo); 
    alert(mapMarkers)
    });
4

1 回答 1

1

试试这个:你需要使用thisin$('.googleMapCity',this).val().googleMapCity进入 current.gmapItems

$("#AddGoogleMap").on('click', function () {            
var mapMarkers = $('.gmapItems').map(function(){
       mapMarker = new Array();
       mapMarker.push($('.googleMapCity',this).val());
       mapMarker.push($('.googleMapAddress',this).val());
       mapMarker.push($('.googleMapInformation',this).val());  
       return mapMarker;
    }).get();
});
于 2013-05-16T09:26:11.987 回答