如何获取循环内单击标记的数据?
How can I get the data of a clicked marker inside a loop?
我正在尝试为 Wordpress 创建 Google 地图插件。
访问:http://andresposadallano.com/sym/tiendas
我有以下 php 循环来显示数据标记。
// Start the Loop
while ( $query->have_posts() ) :
$query->the_post();
$id = get_the_id();
$latitud = get_post_meta($id, 'latitud')[0];
$longitud = get_post_meta($id, 'longitud')[0];
?>
<li>
<a href="" class="point" onclick="show_info(); click_to_move(); return false;" data-title="<?php the_title(); ?>" data-content="<?php the_content(); ?>" data-latitud="<?php echo $latitud ?>" data-longitud="<?php echo $longitud ?>"> <?php the_title(); ?> </a>
</li>
<?php endwhile;
然后,我有以下函数来获取点标题,仅针对点击的点。
function show_info(){
jQuery('#nav-acc a.point').each(function(index){
var tit_t = jQuery(this).data('title');
console.log( index + ': ' + tit_t );
});
}
这里显示了列表中的所有标题,如何只打印点击标记的标题?
您不需要 .each
循环。从 click
事件发送元素并使用它。像这样。
<a href="" class="point" onclick="show_info(this); click_to_move(); return false;"...
//.... ^^^^
function show_info(elem){
var tit_t = $(elem).data('title');
console.log( index + ': ' + tit_t );
}
我正在尝试为 Wordpress 创建 Google 地图插件。
访问:http://andresposadallano.com/sym/tiendas
我有以下 php 循环来显示数据标记。
// Start the Loop
while ( $query->have_posts() ) :
$query->the_post();
$id = get_the_id();
$latitud = get_post_meta($id, 'latitud')[0];
$longitud = get_post_meta($id, 'longitud')[0];
?>
<li>
<a href="" class="point" onclick="show_info(); click_to_move(); return false;" data-title="<?php the_title(); ?>" data-content="<?php the_content(); ?>" data-latitud="<?php echo $latitud ?>" data-longitud="<?php echo $longitud ?>"> <?php the_title(); ?> </a>
</li>
<?php endwhile;
然后,我有以下函数来获取点标题,仅针对点击的点。
function show_info(){
jQuery('#nav-acc a.point').each(function(index){
var tit_t = jQuery(this).data('title');
console.log( index + ': ' + tit_t );
});
}
这里显示了列表中的所有标题,如何只打印点击标记的标题?
您不需要 .each
循环。从 click
事件发送元素并使用它。像这样。
<a href="" class="point" onclick="show_info(this); click_to_move(); return false;"...
//.... ^^^^
function show_info(elem){
var tit_t = $(elem).data('title');
console.log( index + ': ' + tit_t );
}